Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of JSON

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shares with you the content of the sample analysis of JSON. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Json

[{"id": 394, "qy_json": "{\" title\ ": [\" serial number\ ",\" license file number\ ",\" license file name\ ",\" valid from\ ",\" valid to\ ",\" license authority\ ",\" license content\ ",\" status\ ",\" details\ "],\" info\ ": [[\" 1\ " \ "(Cheng) change words [2017] No. 000050\",\ "other\",\ "February 11, 1988\",\ "Chengdu Administration for Industry and Commerce\",\ "change" Chengdu Southwest Metallurgical Survey Engineering Company to\ "Sichuan Metallurgical Survey and Engineering Company Huiyu Geographic Information Engineering Company\",\ "effective\",\ "View\"}, "company_id": 26204710 "create_time": 1488327047000}]

The above json is wrong, because there are more Chinese double quotes to change the "Chengdu Southwest Metallurgical Survey Engineering Company" here. Let's see how to solve it.

1. The analysis shows that this is an array json.

two。 There is also nesting in the array

3. Arrays in nesting are not traditional colons: separated, but presented in the corresponding way of the array.

Resolution steps

1. Traversing array json

For (int I = 0; I < array.size (); iTunes +) {B_admin_licens xzxk = new B_admin_licens (); String json = array.getString (I)

two。 Get the array string and preprocess the problem of double quotation marks

Json = json.replace ("", "); json = json.replace (",")

3. The string is transferred to the json object jsont,jsont to retrieve the corresponding value

JSONObject jsont = JSON.parseObject (json); Object id = jsont.get ("id"); Object company_id = jsont.get ("company_id")

4. How to get nested value? Jsont takes out the corresponding value value and converts it into a string type, and then converts qy_str into a json object before the array can be retrieved.

String qy_str = jsont.getString ("qy_json"); JSONObject qy_json = JSON.parseObject (qy_str); JSONArray info_array = qy_json.getJSONArray ("info"); JSONArray title = qy_json.getJSONArray ("title")

5.info is an array nested array, so you have to loop twice to get it out.

For (int j = 0; j < info_array.size (); jacks +) {JSONArray info_list = info_array.getJSONArray (j); for (int k = 0; k < info_list.size (); info_list.getString +) {info_list.getString (k);}}

Json escapes data with quotation marks

Value.replace ("\",\")

When json handles multiple double quotes in content, the php side handles

A ='{"name": "John\"\ "Cliff\" Cliff\ "Barxter"}'; dump (json_decode ($a, true)); Thank you for reading! This is the end of this article on "sample Analysis of JSON". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report