Java解析json为JsonObject

导包
```
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
JSONObject data = json.getJSONObject("data");
String str = "{\n" +
        "    \"code\": 0,\n" +
        "    \"msg\": \"操作成功\",\n" +
        "    \"data\": {\n" +
        "        \"sessionId\": \"fdsafdasfdefdassfda\",\n" +
        "        \"msgId\": \"08846110-6175-4050-a87e-7ff51a2c0790_1524646704115\",\n" +
        "        \"answerType\": \"7\",\n" +
        "        \"guideList\": [\n" +
        "            {\n" +
        "                \"order\": \"1\",\n" +
        "                \"question\": \"玩玩啊1\",\n" +
        "                \"question_id\": \"e2dbfda3-4219-11e8-bb48-0026b961fb7b\",\n" +
        "                \"weight\": 1,\n" +
        "                \"kbName\": \"关联问题测试\",\n" +
        "                \"content\": \"来啊,快活啊\",\n" +
        "                \"msgType\": \"text\"\n" +
        "            },\n" +
        "            {\n" +
        "                \"order\": \"2\",\n" +
        "                \"question\": \"玩玩2\",\n" +
        "                \"question_id\": \"e6bf08b0-4219-11e8-bb48-0026b961fb7b\",\n" +
        "                \"weight\": 1,\n" +
        "                \"kbName\": \"关联问题测试\",\n" +
        "                \"content\": \"水电费\",\n" +
        "                \"msgType\": \"text\"\n" +
        "            },\n" +
        "            {\n" +
        "                \"order\": \"3\",\n" +
        "                \"question\": \"玩玩3\",\n" +
        "                \"question_id\": \"eac14cb9-4219-11e8-bb48-0026b961fb7b\",\n" +
        "                \"weight\": 1,\n" +
        "                \"kbName\": \"关联问题测试\",\n" +
        "                \"content\": \"3\",\n" +
        "                \"msgType\": \"text\"\n" +
        "            },\n" +
        "            {\n" +
        "                \"order\": \"4\",\n" +
        "                \"question\": \"玩玩4\",\n" +
        "                \"question_id\": \"ee59d09e-4219-11e8-bb48-0026b961fb7b\",\n" +
        "                \"weight\": 1,\n" +
        "                \"kbName\": \"关联问题测试\",\n" +
        "                \"content\": \"4\",\n" +
        "                \"msgType\": \"text\"\n" +
        "            },\n" +
        "            {\n" +
        "                \"order\": \"5\",\n" +
        "                \"question\": \"玩玩5\",\n" +
        "                \"question_id\": \"f1f2f867-4219-11e8-bb48-0026b961fb7b\",\n" +
        "                \"weight\": 1,\n" +
        "                \"kbName\": \"关联问题测试\",\n" +
        "                \"content\": \"5.腰疼,不来了\",\n" +
        "                \"msgType\": \"text\"\n" +
        "            }\n" +
        "        ],\n" +
        "        \"answerList\": [\n" +
        "            {\n" +
        "                \"answer\": \"来啊,快活啊\",\n" +
        "                \"weight\": 0.5995264,\n" +
        "                \"msgType\": \"text\"\n" +
        "            }\n" +
        "        ],\n" +
        "        \"guideText\": \"范围呢引导问题:\",\n" +
        "        \"evaluateSwitch\": null\n" +
        "    }\n" +
        "}";
JSONObject json = JSON.parseObject(str);
JSONObject data =  json.getJSONObject("data");
删除JsonObject 中的某个字段用
data.remove("sessionId");
System.out.println(data);
```


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值