What's the C# solution to decode a json string into string array, without knowing the class variables? It must be compatible with .Net 3.5 or .Net4.0, as I have to support older version of Unity.
below is my json return from a web request. There is no guarantee if their json format will change in the future or not. Thus, json object array, or dictionary style would solve my concern.
{"items":[{
"price":"10.00",
"downloaded":"Yes",
"date":"2022-01-01",
"quantity":"1",
"reason":null,
"other_license":"No",
"package":"packageName",
"currency":"EUR",
"refunded":"No",
"invoice":"IN0123456789",
"MoreItem1":"value",
"MoreItem2":"value",
"MoreItem3":"value"
}]}
I found this method from other post, but it cause error of "Unexpected node type".
private struct JsonArrayWrapper<T>
{
public T wrap_result;
}
public static T ParseJsonArray<T>(string json)
{
var temp = JsonUtility.FromJson<JsonArrayWrapper<T>>("{\"wrap_result\":" + json + "}");
return temp.wrap_result;
}
//below lines cause error
string[] options = ParseJsonArray<string[]>(json);
for (int i = 0; i < options.Length; i++)
{
Debug.Log(options[i]);
}
Any suggestion will be very much appreciated.