jquery handles json objects_jquery
May 16, 2016 pm 04:32 PMphp script on server side:
<?php
$data['id'] = 1;
$dat['name'] = "mary";
$da['red']= array_merge($data,$dat);
$data1['id'] = 2;
$dat1['name'] = "Swallow";
$da['blue']= array_merge($data1,$dat1);
print_r($da); //The printout is a two-dimensional array (as shown below)
/*
Array
(
[red] => Array
(
[id] => 1 [name] => ) )
[blue] => Array
(
[id] => 2 [name] => ) )
)
*/
echo json_encode($da);//The output is a string converted into json format, which can be used directly in js (as follows)
/*
{"red":{"id":1,"name":"mary"},"blue":{"id":2,"name":"u71d5u5b50"}}
*/
?>
jquery script:
Processing after returning to js:
Copy code
alert(item.id "Haha" item.name);
})
The second type: does not require conversion:
Copy code
})
There are also two methods of looping:
Copy code
alert(item.id "Haha" item.name); })
//Method 2:
for(var key in arr){
alert(key);
alert(arr[key].status);

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of jQuery reference methods: Quick start guide

How to use PUT request method in jQuery?

How to remove the height attribute of an element with jQuery?

jQuery Tips: Quickly modify the text of all a tags on the page

In-depth analysis: jQuery's advantages and disadvantages

Use jQuery to modify the text content of all a tags

Understand the role and application scenarios of eq in jQuery

How to tell if a jQuery element has a specific attribute?
