java如何提取json数据,如何使用Java提取JSON数据

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值