When developing, json json objects silly string, and could not tell after ajax asynchronous request, the request will be successful return value determination according to data, access will prompt data.msg 'undefined', to convert the data objects to json.
A, json objects, distinction json string
. 1, the object json
json objects, attributes json object can be an object. Property called. It can clearly be seen by the console: * the console.log json object () can be used alone console console output json object, the result is the Object; * json property access objects: Object Attribute Type * json object can typeof () View of type Object;
2, json string
json string is a string caused by a single or double quotes, because the format string conforms json format, so called json string. Can clearly be seen by Console: * the console.log JSON string () output { "name": "static", "age": "19 ", "sex": " F"}, if no external there are single and double quotation marks to distinguish jso string or json object. here it is easy to be misled. Json alone console console output string, the result "{" name ":" static "," age ":" 19 "," sex ":" F "}"; * without string json attribute value, if mistaken json is the object, property access by the string, the result is undefined, the need to convert the string to json json to access the object;. * json object type () can be viewed by typeof, string type;
Second, the conversion and json json string object
. 1, a string transfer json json object method call parse
2, json json string into the object, call the JSON.stringify () method
|
|