Working with LitJson in C# in Unity

佐手、 提交于 2019-12-13 05:24:39

问题


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


回答1:


The keys method of the JSONObject class returns an ICollection<string>. You can iterate an ICollection like this. So I would change your while loop into a foreach, like this:

foreach (string key in keys) {
    //whatever
}


来源:https://stackoverflow.com/questions/27600792/working-with-litjson-in-c-sharp-in-unity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!