android java 数组转字符串,如何在Android中将表的数据行的JSON格式字符串转换为Java数组...

I have a JSON string like this of data for a table in an android app. one of {} is a row of data for the table. I want to separate these {}s into an array and then each element inside this array into other sub-arrays separating other elements inside {}. Please suggest an appropriate way of accomplishing this criteria using JSON. Thank you.

[

{

"nodeName":"prime_mtsc22@smpp3",

"nodeId":"MTSC3",

"tidPrefix":"4",

"optStatus":"offline",

"daStart":"1",

"daEnd":"3",

"description":"Description"

},

{

"nodeName":"prime_mtsc22@smpp2",

"nodeId":"MTSC58",

"tidPrefix":"1",

"optStatus":"blocked",

"daStart":"5",

"daEnd":"10",

"description":"new description"

},

{

"nodeName":"prime_mtsc22@smpp1",

"nodeId":"MTSC1",

"tidPrefix":"15",

"optStatus":"online",

"daStart":"12",

"daEnd":"20",

"description":"Description"

},

{

"nodeName":"prime_mtsc22@smpp0",

"nodeId":"MTSC15",

"tidPrefix":"15",

"optStatus":"offline",

"daStart":"25",

"daEnd":"30",

"description":"Description"

}

]

解决方案

ok so in that case the code to use is this

String jsonString = ;

// THIS IS NOT NEEDED ANYMORE

//JSONObject json = new JSONObject(jsonString);

JSONArray topArray = null;

try {

// Getting your top array

// THIS IS NOT NEEDED ANYMORE

//topArray = json.getJSONArray(jsonString);

//use this instead

topArray = new JSONArray(jsonString);

// looping through All elements

for(int i = 0; i < topArray.length(); i++){

JSONObject c = topArray.getJSONObject(i);

//list holding row data

List nodeList = new ArrayList();

// Storing each json item in variable

String nodeName = c.getString("nodeName");

String nodeID = c.getString("nodeID");

NodePOJO pojo = new NodePOJO();

pojo.setNodeName(nodeName);

//add rest of the json data to NodePOJO class

//the object to list

nodeList.add(pojo);

}

} catch (JSONException e) {

e.printStackTrace();

}

ok?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值