0

如何使用 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"}}] 
4

2 回答 2

1

试试这个 :

演示

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>");
    });
于 2013-03-21T03:16:25.143 回答
0

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

$.each(json_data, function (index, customer){//here json_data is success response from the Server
if (customer){
console.log(customer["customers_firstname"];
}
})
于 2013-03-21T03:11:49.957 回答