JSON error 415 400

Source: Internet
Author: User

JSOperation JSONSummarize
$(function() {$.ajax ({method:' Post ', URL:'/starmooc/forum/getsectionlist ', DataType:' JSON ', data:{"UserId": "123456",                   "Usertype": "1",                   "Pagenum": 1,                   "PageSize": 5}}). Done (function(data) {Console.log (data)varhtml = template (' forum-lists '), Data.data); $(". Content"). HTML (HTML);            }); });

Error 415 Workaround contenttype: ' Application/json ', continue error 400 solution data:JSON.stringify (pamares)
$(function(){        varparams = {                   "UserId": "123456",                   "Usertype": "1",                   "Pagenum": 1,                   "PageSize": 5        }; $.ajax ({method:' Post ', URL:'/starmooc/forum/getsectionlist ', DataType:' JSON ', ContentType:' Application/json ', Data:JSON.stringify (Pamares)}). Done (function(data) {Console.log (data)varhtml = template (' forum-lists '), Data.data); $(". Content"). HTML (HTML);            });    }); 

JSON (JavaScript Object Notation) is a lightweight data interchange format that is ideal for data interchange formats with completely language-independent text formatting. At the same time,JSON is a native JavaScript format, which means that working with JSON data in JavaScript does not require any special APIs or toolkits.

This article is mainly to the JS operation JSON Essentials to do a summary.

In JSON , there are two kinds of structures: objects and arrays.

1. An object starts with "{" (opening parenthesis) and "}" (the closing parenthesis) ends. Each "name" is followed by a ":" (colon); "' Name/value ' pairs" are separated by "," (comma). The name is enclosed in quotation marks, and if the value is a string, it must be in parentheses, and the numeric type is not required. For example:

var o={"Xlid": "Cxh", "Xldigitid": 123456, "Topscore": $, "topplaytime": "2009-08-20"};

2. An array is an ordered collection of values (value). An array begins with "[" (the left square bracket), and "]" (the right square bracket) ends. Use "," (comma) to separate values.

For example:

var jsonranklist=[{"Xlid": "Cxh", "Xldigitid": 123456, "Topscore": $, "topplaytime": "2009-08-20"},{"Xlid": "Zd", " Xldigitid ": 123456," Topscore ":" Topplaytime ":" 2009-11-20 "}];

JSON provides JSON for easy processing of json data. JS package,: http://www. json. org/json. JS

In The data transfer process,JSON is passed in the form of text, which is a string, and JS operates on JSON objects, soJSON objects and JSON The mutual conversion between strings is key. For example:

JSON String:

var str1 = ' {' name ': ' cxh ', ' sex ': ' Man '} ';

JSON object:

var str2 = {"Name": "Cxh", "Sex": "Man"};

One,json string converted to JSON object

To use the above str1, you must use the following to turn the lead into a JSON object:

Convert from JSON string to json object

var obj = eval (' (' + str + ') ');

Or

var obj = Str.parsejson (); Convert from JSON string to json object

Or

var obj = JSON. Parse (str); Convert from JSON string to json object

Then, you can read this:

Alert (Obj.name);

Alert (Obj.sex);

Special attention: If obj is originally a JSON object, then the use of the Eval () function after conversion (even if multiple conversions) is a JSON object, but the use of the Parsejson () function will be problematic (throwing a syntax exception).

Second, you can use toJSONString () or Global Essentials JSON. Stringify () Converts the JSON object to a JSON string.

For example:

var last=obj.tojsonstring (); Convert a JSON object to a JSON character

Or

var last=JSON. stringify (obj); Convert a JSON object to a JSON character

alert (last);

Pay attention:

In the above multiple essentials, in addition to the eval () function is js self-contained, many other essentials are from the JSON. JS package. The new version of JSON modifies the API to inject json. Stringify () and json. Parse () Two essentials into Javascript's built-in object, which becomes an object . toJSONString (), while the latter becomes String.parsejson (). If you are prompted not to find the tojsonstring () and Parsejson () Essentials, your JSON package version is too low

http://cache.baiducontent.com/c?m= 9f65cb4a8c8507ed4fece763105392230e54f73260878e482a958448e435061e5a23befb73745053809a613441e9120db4a7776f340827b39dce835dd dccc86e70d633712d5cd04e4a920eafba1e649c7c&p=866a8b15d9c041ac1dbe9b7c5c7ac9&newp= C96a8615d9c041ac1ebe9b7c455985231610db2151d4d6166b82c825d7331b001c3bbfb42324130ed0ce776205ae485be0fa30723d0923a3dda5c91d9 Fb4c57479ce&user=baidu&fm=sc&query=js++josn&qid=efbfbf640000d12f&p1=1

JSON error 415 400

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.