$. Ajax cannot parse json objects. The cause and solution of InvalidJSON error are reported.

Source: Internet
Author: User
1 pages introduce jqueryjson-22js and jquery-1102minjs versions that can be controlled by yourself this can be seen from $ parseJSON (json) That parseJSON's interpretation in the document is: accept a JSON string and return the parsed object. Input an exception

1. Pages introduced jquery. json-2.2.js and jquery-1.10.2.min.js versions can be controlled by yourself


We can see from $. parseJSON (json) That parseJSON is interpreted:

Accepts a JSON string and returns the parsed object.

Inputting a malformed JSON string throws an exception. For example, the following are malformed JSON strings:
{Test: 1} (test is not surrounded by double quotation marks) // key
{'Test': 1} (using single quotes instead of double quotes) // key


Here is an example.

Var data = '[{"time": "10:25:36" },{ "starttime": "09:00:00" },{ "endtime": "12:00:00"}]';

Var msg = $. parseJSON (data); understand the usage of $. parseJSON (). This function accepts a JSON string and returns the parsed object.
Var time = msg [0]. time;
Var start = msg [1]. starttime;
Var end = msg [2]. endtime;
Alert (time); // value: 10:25:36
Alert (start); // value: 09:00:00
Alert (end); // value: 12:00:00

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.