json 数组 js 获取值!



 {
"rows":5,
"result":[
[{"item_id":"60","item_no":"0101010001","item_huo":"00001","item_name":"\u6563\u53f6\u751f\u83dc","item_price":"4.760","item_unit":"\u516c\u65a4","item_scale":"\u8ba1\u91cd","item_rem":"SYSC","stock_id":"87","stock_num":"0","stock_date":"2014-06-05 16:40:43","stock_weight":"0.000"}],

[{"item_id":"61","item_no":"0101010003","item_huo":"00003","item_name":"\u6cb9\u9ea6\u83dc","item_price":"4.360","item_unit":"\u516c\u65a4","item_scale":"\u8ba1\u91cd","item_rem":"YMC","stock_id":"88","stock_num":"0","stock_date":"2014-06-05 16:51:41","stock_weight":"0.000"}],

[{"item_id":"62","item_no":"0101010005","item_huo":"00005","item_name":"\u833c\u84bf","item_price":"7.760","item_unit":"\u516c\u65a4","item_scale":"\u8ba1\u91cd","item_rem":"TH","stock_id":"89","stock_num":"0","stock_date":"2014-06-05 16:51:45","stock_weight":"0.000"}],

[{"item_id":"63","item_no":"0101010006","item_huo":"00006","item_name":"\u82a6\u84bf","item_price":"5.760","item_unit":"\u516c\u65a4","item_scale":"\u8ba1\u91cd","item_rem":"LH","stock_id":"90","stock_num":"0","stock_date":"2014-06-05 16:51:46","stock_weight":"0.000"}],

[{"item_id":"64","item_no":"0101010008","item_huo":"00008","item_name":"\u5c0f\u83e0\u83dc","item_price":"5.960","item_unit":"\u516c\u65a4","item_scale":"\u8ba1\u91cd","item_rem":"XBC","stock_id":"91","stock_num":"0","stock_date":"2014-06-05 16:51:47","stock_weight":"0.000"}]
]
}

JSON 怎么获取 result 的值?

json JavaScript

Kreutz 10 years, 8 months ago

 <script>
    var str = {"rows":5,"result":[[{"item_id":"60","item_no":"0101010001","item_huo":"00001","item_name":"\u6563\u53f6\u751f\u83dc","item_price":"4.760","item_unit":"\u516c\u65a4","item_scale":"\u8ba1\u91cd","item_rem":"SYSC","stock_id":"87","stock_num":"0","stock_date":"2014-06-05 16:40:43","stock_weight":"0.000"}],[{"item_id":"61","item_no":"0101010003","item_huo":"00003","item_name":"\u6cb9\u9ea6\u83dc","item_price":"4.360","item_unit":"\u516c\u65a4","item_scale":"\u8ba1\u91cd","item_rem":"YMC","stock_id":"88","stock_num":"0","stock_date":"2014-06-05 16:51:41","stock_weight":"0.000"}],[{"item_id":"62","item_no":"0101010005","item_huo":"00005","item_name":"\u833c\u84bf","item_price":"7.760","item_unit":"\u516c\u65a4","item_scale":"\u8ba1\u91cd","item_rem":"TH","stock_id":"89","stock_num":"0","stock_date":"2014-06-05 16:51:45","stock_weight":"0.000"}],[{"item_id":"63","item_no":"0101010006","item_huo":"00006","item_name":"\u82a6\u84bf","item_price":"5.760","item_unit":"\u516c\u65a4","item_scale":"\u8ba1\u91cd","item_rem":"LH","stock_id":"90","stock_num":"0","stock_date":"2014-06-05 16:51:46","stock_weight":"0.000"}],[{"item_id":"64","item_no":"0101010008","item_huo":"00008","item_name":"\u5c0f\u83e0\u83dc","item_price":"5.960","item_unit":"\u516c\u65a4","item_scale":"\u8ba1\u91cd","item_rem":"XBC","stock_id":"91","stock_num":"0","stock_date":"2014-06-05 16:51:47","stock_weight":"0.000"}]]};
    alert(str.rows);
    for ( var p in str.result ){ // 方法 
        alert(str.result[p][0].item_id);
    }
</script>

很简单的,多用搜索啊哥。。

条纹大果冻 answered 10 years, 8 months ago

Your Answer