如何使用jQuery访问一点JSON?
我认为这是一个简单的问题,我以前从未使用过JSON 很简单,我有一个JSON对象:如何使用jQuery访问一点JSON?,jquery,json,Jquery,Json,我认为这是一个简单的问题,我以前从未使用过JSON 很简单,我有一个JSON对象: fc_json = { "product_count": 1, "total_price": 199.95, "total_weight": 1, "session_id": "26e8og4ldmlunj84uqf04l8l25", "custom_fields":{ "affiliateID":"25" }, "messages":{ "errors":[],
fc_json = {
"product_count": 1,
"total_price": 199.95,
"total_weight": 1,
"session_id": "26e8og4ldmlunj84uqf04l8l25",
"custom_fields":{
"affiliateID":"25"
},
"messages":{
"errors":[],
"warnings":[],
"info":[]
}
};
我想使用jQuery提取affiliateID的变量。有没有一个简单的方法可以做到这一点?我真的不知道。访问JSON对象不需要jQuery。事实上,JSON对象是JavaScript对象 你应该能做到
alert(fc_json.custom_fields.affiliateID) // alerts 25
与任何其他Javascript对象一样,您也可以通过以下方式访问它:
fc_json['custom_fields']['affiliateID'] // Returns "25"