当前位置:网站首页>Jsonobject jsonarray for parsing

Jsonobject jsonarray for parsing

2022-06-11 05:39:00 Zippx.

Bean Class resolution exception There are always a group of ** Make a mess of the interface Lead to bean Class is particularly rare Causes the programmer to crash Next, I will give you a detailed answer

1.JSONObject:
JSONObject It's just a data structure , It can be understood as JSON Format data structure (key-value structure ), have access to put Methods json Object to add elements .

JSONObject It can be easily converted into a string , You can also easily convert other objects into JSONObject object .

2.JSONArray:
JSONArray Is an ordered sequence of values . Its external text form is a string enclosed in square brackets , Separate values with commas .

The internal form has The object of the index get and opt Used to access values by index element Method , And methods for adding or replacing values .

3. When parsing interfaces, you will encounter interfaces with internal confusion , There are two kinds of errors in parsing this case : bean Class collection field error And inner classes are the forms of Chinese characters

4. In this case , You need to write an entity class manually according to the field :
Then create an entity class object :
Defining a string , The string content is the data in your interface :
What I recommend is Use JSONObject jsonArray Conduct Bean Class parsing processing First put the parsed data into a string And then through the JSONObject jsonArray Conduct json String parsing processing

5. View the data in the interface , If the field contains {} , That's it object, If it is [] That's it array Then parse the data and add it to the entity class

6. If you encounter any interface internal field problems in the future , Can use this method to solve , What this method needs to pay attention to is to add the data in the field to the entity class

There are two kinds of errors in parsing this case bean Class collection field error And inner classes are the forms of Chinese characters

 Insert picture description here
The most effective solution Is to knock an entity class by hand According to the required fields Write entity classes This is more efficient
 Insert picture description here

What I recommend is Use JSONObject jsonArray Conduct Bean Class parsing processing

First put the parsed data into a string Inside the string
 Insert picture description here

And then through JSONObject jsonArray Conduct json String parsing processing
 Insert picture description here
 Insert picture description here
Is to encounter all json String exception Or parse error You can use JSONObject jsonArray Conduct Bean Class parsing processing

原网站

版权声明
本文为[Zippx.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020537213547.html