Jquery Json提取节点?

时间:2013-03-21 03:08:31

标签: jquery ajax json

如何使用Jquery仅从json格式中提取'customers_firstname'?

<?php echo json_encode($users) ?>

输出

[{"Customer":{"id":"13","customers_gender":"M","resumetest":"a15ff2aa27d616636b5bc30fac4dba38733f4e5f","created":"2013-01-29 13:49:06","modified":"2013-03-14 11:50:18","customers_firstname":"Gerald","customers_lastname":"Russ"}},{"Customer":{"id":"14","customers_gender":"F","resumetest":null,"created":"2013-01-29 15:41:23","modified":"2013-02-14 15:08:42","customers_firstname":"Jim","customers_lastname":"Carrie"}}] 

2 个答案:

答案 0 :(得分:1)

试试这个:

DEMO

HTML

<ul id="nameList">
</ul>

<强> JS

var customers = [{"Customer":{"id":"13","customers_gender":"M","resumetest":"a15ff2aa27d616636b5bc30fac4dba38733f4e5f","created":"2013-01-29 13:49:06","modified":"2013-03-14 11:50:18","customers_firstname":"Gerald","customers_lastname":"Russ"}},{"Customer":{"id":"14","customers_gender":"F","resumetest":null,"created":"2013-01-29 15:41:23","modified":"2013-02-14 15:08:42","customers_firstname":"Jim","customers_lastname":"Carrie"}}];

$.each(customers, function (index, item) {

        $("#nameList").append("<li>" + item.Customer.customers_firstname + "</li>");
    });

答案 1 :(得分:0)

您可以在AJAX成功块中使用以下代码

$.each(json_data, function (index, customer){//here json_data is success response from the Server
if (customer){
console.log(customer["customers_firstname"];
}
})