我有这个JSON对象,我想用javascript或jquery导航它,我该怎么做?
class
编辑:
请我收到此错误:
未捕获的TypeError:无法读取未定义的属性'product_id'
我尝试过这些并没有成功:
{
"Fporder": {
"cep_id": "300000007",
"user_id": "300000192",
"fporder_type_id": 2,
"agency_id": null,
"fporder_code": 1,
"id": "66"
},
"FpordersProduct": [
{
"product_id": "1938",
"requested": "4",
"price": 3965,
"product_name": "PLANCHA DE LASAGNA PRE COCIDO X KL",
"product_code": "22044001"
}
]
}
OR
json_object.FpordersProduct.product_id
OR
json_object.FpordersProduct[0].product_id
但它不起作用。请帮助。
EDIT2
json_object.FpordersProduct[0]['product_id']
答案 0 :(得分:0)
嗯,“浏览它”非常模糊。但是,它是一个对象,所以如果你需要做的就是访问它的属性,你可以像任何其他对象一样。
示例:
var some_json_object = {
"Fporder": {
"cep_id": "300000007",
"user_id": "300000192",
"fporder_type_id": 2,
"agency_id": null,
"fporder_code": 1,
"id": "66"
},
"FpordersProduct": [
{
"product_id": "1938",
"requested": "4",
"price": 3965,
"product_name": "PLANCHA DE LASAGNA PRE COCIDO X KL",
"product_code": "22044001"
}
]
}
some_json_object.Fporder // to access Fporder property on root of object
some_json_object.Fporder.cep_id // to access cep_id property on the object assigned to the Fporder property
some_json_object.FpordersProduct[0] // to access the first (currently only) object on the array assigned to the FpordersProduct property
// ... etc.