Why do I use Object1.optint, and object1.optstring, during the JSON parsing process?

Source: Internet
Author: User

Today in the JSON parsing, there was a piece of code did not execute the problem, and then looked for a reason:

1, the original code is:

found that the red sentence did not execute, view the console found an exception

2, fix the bug, the correct code for

3. Summary

1, we parse the method GetString ("") is because the JSON does not exist in this value, will report an exception, resulting in the following code will not execute

2, security I generally use optstring method, this way will not report abnormal

3,object1.optint ("id") does not exist this value, return 0

Object1.optstring ("mobile") does not exist for this value and returns an empty

Why do I use Object1.optint, and object1.optstring, during the JSON parsing process?

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.