mirror of
https://github.com/json-iterator/go.git
synced 2025-01-05 12:50:34 +02:00
#126 fix space in case map key is sorted
This commit is contained in:
parent
d37197e176
commit
845d8438db
@ -101,9 +101,10 @@ func (encoder *mapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
||||
stream.WriteMore()
|
||||
}
|
||||
encodeMapKey(key, stream)
|
||||
stream.writeByte(':')
|
||||
if stream.indention > 0 {
|
||||
stream.writeByte(' ')
|
||||
stream.writeTwoBytes(byte(':'), byte(' '))
|
||||
} else {
|
||||
stream.writeByte(':')
|
||||
}
|
||||
val := realVal.MapIndex(key).Interface()
|
||||
encoder.elemEncoder.EncodeInterface(val, stream)
|
||||
@ -185,7 +186,11 @@ func (encoder *sortKeysMapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
||||
stream.WriteMore()
|
||||
}
|
||||
stream.WriteVal(key.s) // might need html escape, so can not WriteString directly
|
||||
stream.writeByte(':')
|
||||
if stream.indention > 0 {
|
||||
stream.writeTwoBytes(byte(':'), byte(' '))
|
||||
} else {
|
||||
stream.writeByte(':')
|
||||
}
|
||||
val := realVal.MapIndex(key.v).Interface()
|
||||
encoder.elemEncoder.EncodeInterface(val, stream)
|
||||
}
|
||||
|
@ -78,4 +78,7 @@ func Test_marshal_indent_map(t *testing.T) {
|
||||
output, err = MarshalIndent(obj, "", " ")
|
||||
should.Nil(err)
|
||||
should.Equal("{\n \"1\": 2\n}", string(output))
|
||||
output, err = ConfigCompatibleWithStandardLibrary.MarshalIndent(obj, "", " ")
|
||||
should.Nil(err)
|
||||
should.Equal("{\n \"1\": 2\n}", string(output))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user