600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > String类型转换成json对象

String类型转换成json对象

时间:2021-06-19 18:35:38

相关推荐

String类型转换成json对象

1:添加依赖:

<!-- json依赖 --><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.47</version></dependency>

2:类型转换

String count = SendRequest.sendPostJson(url, jsonObject, headerMap);//返回查询结果

JSONObject jsonObject1 = JSONObject.parseObject(count);

字符串转json对象

JSONArray json = jsonObject1.getJSONArray("MsgList");//获取json对象中的数组元素

Object msgTime = json.getJSONObject(i).get("MsgTimeStamp");获取json对象中的普通元素

Object jsons1 = jsons.getJSONObject(0).get("MsgContent");//获取json数组中的对象jsonJSONObject value = (JSONObject)jsons1;转换成Json对象String msgs =(String) value.get("Text");//获取json格式中的value值

获取短信code。

{"RequestId":"eea051f1-de0a-441b-b9e3-53d2d56f8b00","SendStatusSet":[{"SerialNo":"2640:197962777016543062170869446","IsoCode":"CN","Message":"send success","Fee":1,"PhoneNumber":"+8613677494463","SessionContext":"","Code":"Ok"}]}

SendSmsResponse resp = client.SendSms(req);// 输出json格式的字符串回包

1:转换成json

JSONObject jsonObjects = JSONObject.parseObject(count);//转换成json

2:获取数组:

JSONArray json = jsonObjects.getJSONArray("SendStatusSet");//获取json对象中的数组元素

3:直接获取数组中的元素:

json.getJSONObject(0).get("Code");msg = json.getJSONObject(0).get("Code").toString();

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。