Java中把字符串转为Json对象

“绿遍山原白满川,子规声里雨如烟”
在调用别人的接口时,人家返回的是一串json的字符串,这时我需要把字符串转成json,然后获取里面对应的key值。
返回的字符串是这样的:

{"Response":{"ErrorInfo":{"Uuid":"a9dfs92c-6530-4dse-94b5-72896547a614","TransactionId":"BD46542185154851","TokenId":null,"DealTime":"0.030","ErrorDtl":null,"Message":"成功","BusiCode":"OI_SendShortMessage","ServerName":"crm_ec_http_b_18317","TransactionTime":"BD46542185154851","Code":"0000","ExtInfo":{}},"RetInfo":{}}}

写代码解析这段字符串:

//先转成json对象
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(httpPost);
//再获取里面的message对应的值
jsonObject.getJSONObject("Response").getJSONObject("ErrorInfo").get("Message").toString()

结果如图:
Java中把字符串转为Json对象_第1张图片

你可能感兴趣的:(java)