Java representation of JSON Object

后端 未结 2 517
醉话见心
醉话见心 2021-01-24 02:34

I am trying to deserialize the following string, I am somewhat new to java and I cannot get this to work for the life of me... I am only trying to decode two strings in the obje

相关标签:
2条回答
  • 2021-01-24 03:00

    Here are some nice Tutorials for JSON that will help you out.

    GSON

    JSON

    JSON Example with source code

    UPDATED

    Try like this,

     try {
                JSONObject object = new JSONObject(jsonString);
                JSONObject myObject = object.getJSONObject("recentlyMarkedTerritories");
    
                for (int i = 0; i < object.length(); i++) {
                    JSONObject myObject2 = myObject.getJSONObject(Integer.toString(i));
                    System.out.println(myObject2.toString(2));  
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
    
    0 讨论(0)
  • 2021-01-24 03:02

    I am not sure of the gson code to write, but the structure of your json looks more like the following java representation (though you might want booleans and ints instead of String fields):

    public class RecentActivity {
        String result;
        Map<String,RecentlyMarkedTerritory> recentlyMarkedTerritories = null;
    }
    
    public class RecentlyMarkedTerritory {
        String pk_activity;
        // other fields
    }
    
    0 讨论(0)
提交回复
热议问题