Home > Java > javaTutorial > body text

What does json format error mean?

(*-*)浩
Release: 2019-05-20 16:16:52
Original
11431 people have browsed it

Json format error is generally caused by a problem between the json data on the server side and the parsing format of your client.

What does json format error mean?

Solution:

1, Use org.json.JSONObject to parse from When getting json data from the network, I encounter JSONException: java.lang.String cannot be converted to JSONObject. There is no problem when printing the string and checking the json string;

What does json format error mean?

2, The reason for the problem is that when writing the json file, utf-8 encoding is used. utf8 has a BOM format, and it will be ok if you remove this format;

3 , Another way is to remove the BOM header in the java code. What does json format error mean?

The Select method reprojects the object collection and converts the Birthday attribute into a new attribute. Note that the attribute must be renamed after it is changed. The attribute name can be the same; you can use the select method or LINQ query expression here. , you can also choose other methods to achieve the same purpose; this method can remove attributes that are not used by the client in the collection to achieve the purpose of simply optimizing performance.

The backend provides APIs for front-end calls. Generally, HttpMessageConverter is used to convert Json strings into objects. If there is a format problem, an exception HttpMessageNotReadableException will be thrown. However, the original Json string cannot be obtained in the background, and it is inconvenient to locate the exact format error. This article introduces a simple method to display the original Json information when an error occurs.

At first I wanted to find other ways. When an exception is thrown, read the body content from HttpServletRequest. But it can't be done because when reading Json, the InputStream has been read and the body content cannot be obtained again. So you can customize MessageConverter.

The above is the detailed content of What does json format error mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!