Bunny83 / SimpleJSON

A simple JSON parser in C#
MIT License
735 stars 294 forks source link

String Array: Returned with Quotes, bug? #18

Closed plmayer closed 6 years ago

plmayer commented 6 years ago

If you have a string array like this:

"categories": [ "A", "B" ]

which you read like this:

JSONArray arr = o["categories"].AsArray; foreach (JSONNode cat in arr) { Debug.Log(cat); }

You get "A", "B" -- not A, B -- i.e. the quotes are part of cat. AFAIK they shouldn't be, as the type of the array elements is string. Or am I missing something here?

Bunny83 commented 6 years ago

You implicitly use ToString on your "cat" value. ToString on a JSONNode will return the json representation of the node. Since the node is a string node it returns the quoted value. If you want to access the string value, use the "Value" property.

foreach (JSONNode cat in o["categories"])
{
    Debug.Log(cat.Value); 
}
plmayer commented 6 years ago

That makes sense. Thanks!