I am trying to port a piece of Code from Java to C# and I am stuck in JSon parsing. Have a look at the following Java Code
mJsonObject = new JSONObject(str);
Iterator<String> keys=mJsonObject.keys();
while(keys.hasNext()){
String key=keys.next();
String value=mJsonObject.getString(key);
mAdData.add(new AdData(key, new JSONObject(value)));
}
I had a string which has verified Json format and I passed it to JSONObject and every thing was finely working in Java, but now in C# Unity I am not able to port it successful. I am using LitJson to perform this task and I have no idea how this works. I am badly stuck please help. Thanks
The keys method of the JSONObject
class
returns anICollection<string>
. You can iterate anICollection
like this. So I would change yourwhile
loop into aforeach
, like this: