Android determines JSON format and submits error messages to the server

Source: Internet
Author: User

Development found that the server occasionally sends the wrong format JSON to the Android client, causing the Android client JSON parsing to fail and apply the exception.

Instead of having the server intentionally pit the client, the data may be mixed with other data in addition to the correct JSON data when the client requests the server data.

For example:

When thinkphp turns on ' Show_page_trace ' and true, the correct JSON will be followed by HTML code,

Workaround:

1. Set the ' Show_page_trace ' =>false to False. But not very practical, because the server may be a problem, when you need to turn on debug mode


2. Client determines JSON parsing failure, using try catch to determine JSON format


(1) client-side judgment JSON format


(2) The client submits the data to the server via the volley post method


(2) The server obtains the client-submitted information through the I () method, where the I () method is a method in thinkphp, which is the method to get all the submitted information, regardless of the client commits in any way, will get its key value pair


Android determines JSON format and submits error messages to the server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.