- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- /**
- * 测试解析json格式数据
- *
- * @author yangliang
- * @version 1.0
- * @created 2011-12-2 上午09:38:11
- * @history
- * @see
- */
- public class Test3 {
- public static void main(String[] args) {
- String json = "{'num':11,'org':{'orgId':'orgId','orgName':'orgName'},'biz':" +
- "[{'appcode':55,'subscode':'subscode0'},{'appcode':66,'subscode':'subscode1'}]}";
- JSONObject jo = JSONObject.fromObject(json);
- System.out.println(jo.get("num"));
- JSONObject orgJson= jo.getJSONObject("org");
- System.out.println(orgJson);
- System.out.println(orgJson.get("orgId"));
- JSONArray bizJson= jo.getJSONArray("biz");
- System.out.println(bizJson.getJSONObject(0).get("appcode"));
- }
- }
- // 下面是输出结果
- 11
- {"orgId":"orgId","orgName":"orgName"}
- orgId
- 55
Json Gson java解析json
最新推荐文章于 2024-10-11 23:30:34 发布