解析json数据

来源:互联网 发布:大数据对教育的作用 编辑:程序博客网 时间:2024/06/05 08:23
package HttpWeb;


import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


public class TestMingPianJson {
public static void main(String[] args) {
String jsonss=""+
"{'rotation_angle': '0', 'comment': [{ 'item': 'ARV: Antecipa',  'position': '119,251,311,251,311,279,119,279'  }],"+
"'email': [{'item': 'eduardo.sousa@cilo.com.br','position': '120,196,502,196,502,222,120,222' }],"+
"'organization': [{'item': {'name': 'Eduardo Sousa Executive de Contas Senior'}, 'position': '120,536,408,536,408,587,120,587' },"+
        "{'item': {'name': 'Celo'}, 'position': '559,396,849,396,849,496,559,496'}],"+
        "'telephone': [{'item': {'number': '557991427524', 'type': ['cellular', 'voice']},'position': '120,224,347,224,347,247,120,247'},"+
        "{'item': {'number': '40027472', 'type': ['work', 'voice']},'position': '119,311,499,311,499,334,119,334'},"+
        "{'item': {'number': '8004705472', 'type': ['work', 'voice']}, 'position': '119,282,504,282,504,305,119,305' },"+
        "{'item': {'number': '30036472', 'type': ['work', 'voice']},'position': '318,251,583,251,583,279,318,279' } ],"+
        "'url': [{'item': 'www.cilo.com.br', 'position': '121,167,315,167,315,190,121,190'}]}";
//解析json
parseJson(jsonss);
}
public static void parseJson(String jsons){
JSONObject jsonobj=JSONObject.fromObject(jsons);
//获得字符串属性
String rotation_angle=jsonobj.optString("rotation_angle");

System.out.println("rotation_angle:"+rotation_angle);

                //以下是解析jsonarray

JSONArray comment=jsonobj.getJSONArray("comment");
for (int i = 0; i <comment.size(); i++) {
JSONObject jso=comment.optJSONObject(i);
        String item=jso.optString("item");
        String position=jso.optString("position");
        System.out.println("item:"+item);
    System.out.println("position:"+position);
}


}
}
0 0
原创粉丝点击