JSON objects by "{}" to identify a "{}" represents an object, such as { "AreaId": "123"}, the value of the object key-value pairs (key: value).
json_encode()
This function is mainly used for the array and the object, it is converted to the format json
json_encode
(the PHP. 5> = 5.2.0, the PECL JSON> = 1.2.0)
json_encode - coding of variables JSON
Report a bug description
string json_encode (mixed $ value [, int $ options = 0])
Returns the value of the value as JSON
Report a bug parameter
value
to be encoded value, in addition to the resource type, the data can be any type of
function can only accept the UTF-8 encoded data
options
binary mask consisting of the following constants: JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS , JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_UNESCAPED_UNICODE.
the Report bugs a return value
encoding a successful string form represented in JSON or FALSE return failure.
() Get json object with the $ .ajax.
// in which dataType: "json", so that the data back to the format json. If you do not add the article attribute to a string is returned. String object can ( "(" + data + ")") method json turn into an object, but this method is not recommended for the data fetch operation by the above eval. Distinguish data as JSON object or a string, can print alert statement, if it is Object object it is JSON object, if the content was displayed string.
$.ajax( { type : "POST", url : "testjson!getJson.do", dataType:"json", cache:false, async:false, data : "", success : function(data) { //var object = eval("("+data+")"); $.each(data.list,function(index,item){ alert(item.trueName); }) } });