Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of JSON

Shulou Source: shulou.com Published: 2022-06-03 20:09:07 09月27日 Update

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!

Tags: Array content quotation marks analysis valid company engineering engineering company Chengdu example metallurgy character string object file more validity period article processing measurement Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Technology NVidia Docker OPPO Reno