Skip to content

Commit

Permalink
Update TinyJson to '01c586d' commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
novabyte committed Jul 28, 2020
1 parent 525f855 commit 651930a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/Nakama/TinyJson/JsonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ private static object ParseValue(Type type, string json)
valueType = args[1];
}

//Refuse to parse dictionary keys that aren't of type string
// Refuse to parse dictionary keys that aren't of type string
if (keyType != typeof(string))
return null;
//Must be a valid dictionary element
// Must be a valid dictionary element
if (json[0] != '{' || json[json.Length - 1] != '}')
return null;
//The list is split into key/value pairs only, this means the split must be divisible by 2 to be valid JSON
// The list is split into key/value pairs only, this means the split must be divisible by 2 to be valid JSON
var elems = Split(json);
if (elems.Count % 2 != 0)
return null;
Expand Down Expand Up @@ -436,4 +436,4 @@ private static object ParseObject(Type type, string json)
return instance;
}
}
}
}
23 changes: 18 additions & 5 deletions src/Nakama/TinyJson/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static void AppendValue(StringBuilder stringBuilder, object item)
}

var type = item.GetType();
if (type == typeof(string))
if (type == typeof(string) || type == typeof(char))
{
stringBuilder.Append('"');
var str = (string) item;
Expand All @@ -70,9 +70,21 @@ private static void AppendValue(StringBuilder stringBuilder, object item)

stringBuilder.Append('"');
}
else if (type == typeof(byte) || type == typeof(int))
else if (type == typeof(byte) || type == typeof(sbyte))
{
stringBuilder.Append(item.ToString());
stringBuilder.Append(item);
}
else if (type == typeof(short) || type == typeof(ushort))
{
stringBuilder.Append(item);
}
else if (type == typeof(int) || type == typeof(uint))
{
stringBuilder.Append(item);
}
else if (type == typeof(long) || type == typeof(ulong))
{
stringBuilder.Append(item);
}
else if (type == typeof(float))
{
Expand All @@ -82,6 +94,9 @@ private static void AppendValue(StringBuilder stringBuilder, object item)
{
stringBuilder.Append(((double) item).ToString(System.Globalization.CultureInfo.InvariantCulture));
}
else if (type == typeof (decimal)) {
stringBuilder.Append (((decimal) item).ToString (System.Globalization.CultureInfo.InvariantCulture));
}
else if (type == typeof(bool))
{
stringBuilder.Append((bool) item ? "true" : "false");
Expand All @@ -105,7 +120,6 @@ private static void AppendValue(StringBuilder stringBuilder, object item)
stringBuilder.Append(',');
AppendValue(stringBuilder, t);
}

stringBuilder.Append(']');
}
else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>))
Expand Down Expand Up @@ -133,7 +147,6 @@ private static void AppendValue(StringBuilder stringBuilder, object item)
stringBuilder.Append("\":");
AppendValue(stringBuilder, dict[key]);
}

stringBuilder.Append('}');
}
else
Expand Down

0 comments on commit 651930a

Please sign in to comment.