diff --git a/src/neo/SmartContract/JsonSerializer.cs b/src/neo/SmartContract/JsonSerializer.cs index 375709a13d..5ed1369c8c 100644 --- a/src/neo/SmartContract/JsonSerializer.cs +++ b/src/neo/SmartContract/JsonSerializer.cs @@ -48,6 +48,8 @@ public static JObject Serialize(StackItem item) foreach (var entry in map) { + if (!(entry.Key is ByteString)) throw new FormatException(); + var key = entry.Key.GetString(); var value = Serialize(entry.Value); @@ -106,6 +108,7 @@ public static byte[] SerializeToByteArray(StackItem item, uint maxSize) stack.Push(JsonTokenType.EndObject); foreach (var pair in map.Reverse()) { + if (!(pair.Key is ByteString)) throw new FormatException(); stack.Push(pair.Value); stack.Push(pair.Key); stack.Push(JsonTokenType.PropertyName); @@ -115,7 +118,7 @@ public static byte[] SerializeToByteArray(StackItem item, uint maxSize) writer.WriteEndObject(); break; case JsonTokenType.PropertyName: - writer.WritePropertyName(((PrimitiveType)stack.Pop()).GetSpan()); + writer.WritePropertyName(((ByteString)stack.Pop()).GetSpan()); break; case Null _: writer.WriteNullValue();