需要jar包  import org.json.JSONArray;import org.json.JSONObject;
1、简单json解析
String ret ="";
输出结果为以下:
{result:"处理成功",info:"0",sheetid:"2690D6BE-0E8A-4EF0-93E5-34A6048B1E4A",aiid:"A295009E-1337-462F-BBFC-BE425909F4EC"}
JSONObject a = new JSONObject(ret); 
System.out.("result"));
System.out.("info"));
System.out.("sheetid"));
System.out.("aiid"));
2、解析复杂数组式json
输出结果为以下:
[{aiid:"8652DD3D-4554-4297-8C0F-411419637541",WorkflowAlias:"EH",Title:"商机报备审核流程",SheetId:"EH140119003",ActivityName:"团队经理审批",CreatorName:"冼超然",CreatedTime:"2014-1-19 13:45:21",WorkflowName:"商机报备审核流程"},{aiid:"03E8C1ED-C61C-47F0-979F-12B2E2B86176",WorkflowAlias:"EH",Title:"test1",SheetId:"EH140119002",ActivityName:"集客智慧城市办公室审批",CreatorName:"冼超然",CreatedTime:"2014-1-19 13:43:11",WorkflowName:"商机报备审核流程"}]
JSONArray jsonarray = new JSONArray(ret);
安卓在线解析jsonSystem.out.println(jsonarray.length());
for(int i=0;i<jsonarray.length()-1;i++){
JSONObject json= new (i).toString());//将json数组第i项获得设置为JSONObject
result = result+"\'"+String("aiid")+"\',";
}
JSONObject jsonlast = new (jsonarray.length()-1).toString());
result = result+  "\'"+ String("aiid")+"\'";             
System.out.println(result);//此方法可将所需数据解析为数组型  id1,id2,id3

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。