我认为这是一个简单的问题,我之前没有使用JSON。
很简单,我有一个JSON对象:
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的变量。有一个简单的方法吗?我真的不知道。
答案 0 :(得分:11)
您不需要jQuery来访问JSON对象。实际上,JSON对象是一个JavaScript对象。
你应该能够做到
alert(fc_json.custom_fields.affiliateID) // alerts 25
答案 1 :(得分:2)
就像任何其他Javascript对象一样,您也可以使用以下命令访问它:
fc_json['custom_fields']['affiliateID'] // Returns "25"