解析JSON使用jQuery - 没有得到价值
问题描述:
我得到以下从服务器值解析JSON使用jQuery - 没有得到价值
{"status":{"message":"success","code":200},"data":[{"sent":"test","category":"Appo","experience_time":"2014-10-07","sent_id":4501922,"categoryId":4011,"score":"Negative","feature":"emp","op":"challenges"}]}
我需要得到的发送,类别,experience_time,sent_id,得分,功能,运算等价值
我迄今为止尝试过,但没有得到任何价值。
var result = jQuery.parseJSON(data);
$.each(result, function(index, value) {
alert(value.score);
});
答
试试这个,
var jsonString = '{"status":{"message":"success","code":200},"data":[{"sent":"test","category":"Appo","experience_time":"2014-10-07","sent_id":4501922,"categoryId":4011,"score":"Negative","feature":"emp","op":"challenges"}]}';
var result = jQuery.parseJSON(jsonString);
$.each(result.data, function(index, value) {
alert(value.score);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
您需要使用'$。每个(result.data,函数(指数值){});''以来的结果。 data'包含你想要迭代的数组 – 2014-10-29 06:38:58
在调用'jQuery.parseJSON(data)'前确保'data'是一个字符串而不是对象' - 检查你的浏览器控制台是否有任何错误? – 2014-10-29 06:40:07
Thanks.I将尝试 – aniltc 2014-10-29 06:41:12