mirror of
https://github.com/json-iterator/go.git
synced 2025-04-26 11:42:56 +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()
|
stream.WriteMore()
|
||||||
}
|
}
|
||||||
encodeMapKey(key, stream)
|
encodeMapKey(key, stream)
|
||||||
stream.writeByte(':')
|
|
||||||
if stream.indention > 0 {
|
if stream.indention > 0 {
|
||||||
stream.writeByte(' ')
|
stream.writeTwoBytes(byte(':'), byte(' '))
|
||||||
|
} else {
|
||||||
|
stream.writeByte(':')
|
||||||
}
|
}
|
||||||
val := realVal.MapIndex(key).Interface()
|
val := realVal.MapIndex(key).Interface()
|
||||||
encoder.elemEncoder.EncodeInterface(val, stream)
|
encoder.elemEncoder.EncodeInterface(val, stream)
|
||||||
@ -185,7 +186,11 @@ func (encoder *sortKeysMapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
|
|||||||
stream.WriteMore()
|
stream.WriteMore()
|
||||||
}
|
}
|
||||||
stream.WriteVal(key.s) // might need html escape, so can not WriteString directly
|
stream.WriteVal(key.s) // might need html escape, so can not WriteString directly
|
||||||
|
if stream.indention > 0 {
|
||||||
|
stream.writeTwoBytes(byte(':'), byte(' '))
|
||||||
|
} else {
|
||||||
stream.writeByte(':')
|
stream.writeByte(':')
|
||||||
|
}
|
||||||
val := realVal.MapIndex(key.v).Interface()
|
val := realVal.MapIndex(key.v).Interface()
|
||||||
encoder.elemEncoder.EncodeInterface(val, stream)
|
encoder.elemEncoder.EncodeInterface(val, stream)
|
||||||
}
|
}
|
||||||
|
@ -78,4 +78,7 @@ func Test_marshal_indent_map(t *testing.T) {
|
|||||||
output, err = MarshalIndent(obj, "", " ")
|
output, err = MarshalIndent(obj, "", " ")
|
||||||
should.Nil(err)
|
should.Nil(err)
|
||||||
should.Equal("{\n \"1\": 2\n}", string(output))
|
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…
x
Reference in New Issue
Block a user