I am using Unity C# and want to retrieve data from a nested json object sent from my push notification.
The json object looks like this:
{
"aps":
{
"badge":1
,"sound":"default.mp3"
,"alert":"test my push"
}
,"u":"{\"custom\":\"{\"gameid\":\"12345\"}\"}
}
I the retrieve the json like this:
string payload = aboveJsonString;
Hashtable table = (Hashtable)easy.JSON.JsonDecode(payload);
Hashtable data = (Hashtable)easy.JSON.JsonDecode(table["u"].ToString());
Hashtable gamejson =(Hashtable)easy.JSON.JsonDecode(data["custom"].ToString());
Everything is right until the gamejson?
data["custom"] prints {"gameid":"12345"}
gamejson["gameid"] prints nothing?!?
I am kind a lost in this. Can anyone please help me with this and any help is appreciated.
Thanks in advance :-)
You can Use Simple Json as it is best for Unity scripting. and regarding your problem it is escape sequences in your json string. If you are generating this json on your own server. you should avoid it. Otherwise you need to remove escape sequesnces from string before parsing it.