I am unable to pull data from this in java. The problem is that how name_value_list will be fetched afterwards. Thanks in advance.
{
"id" : "ets7qkt1luugsj828jugs8vuq5",
"module_name" : "Users",
"name_value_list" : { "mobile_max_list_entries" : { "name" : "mobile_max_list_entries",
"value" : null
},
"mobile_max_subpanel_entries" : { "name" : "mobile_max_subpanel_entries",
"value" : null
},
"user_currency_id" : { "name" : "user_currency_id",
"value" : "-99"
},
.
.
"user_language" : { "name" : "user_language",
"value" : "en_us"
},
"user_name" : { "name" : "user_name",
"value" : "abcd"
},
"user_number_seperator" : { "name" : "user_number_seperator",
"value" : ","
}
}
}
解决方案
I would say to try using google's Gson() to deserialize.
First, build the entity (or object mapping) classes, something like:
public class MobileMaxListEntry implements Serializable {
@Expose
@SerializedName("name")
private String name;
@Expose
@SerializedName("name")
private String value;
//getters / setters
}
Do this for each entity you have. Then:
public class ValuesList implements Serializable {
@Expose
@SerializedName("mobile_max_list_entries")
private MobileMaxListEntry mobile_max_list_entries;
@Expose
@SerializedName("mobile_max_subpanel_entries")
private MobileMaxSubpanelEntry mobile_max_subpanel_entries;
//getters/setters for everything
}
Then, the response class:
public class MyResponseClass implements Serializable {
@Expose
@SerializedName("id")
private String objectId;
@Expose
@SerializedName("module_name")
private String moduleName;
@Expose
@SerializedName("name_value_list")
private ValuesList valuesList;
//getters / setters for everything
}
Then, finally, in your code:
Gson gson = new Gson();
String json = "your_json_here";
MyResponseClass deserialized = gson.fromJson(json, MyResponseClass.class);
If you get an error, try adding default empty constructors for each class.