Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jQuery访问一点JSON?_Jquery_Json - Fatal编程技术网

如何使用jQuery访问一点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":[],

我认为这是一个简单的问题,我以前从未使用过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的变量。有没有一个简单的方法可以做到这一点?我真的不知道。

访问JSON对象不需要jQuery。事实上,JSON对象是JavaScript对象

你应该能做到

alert(fc_json.custom_fields.affiliateID) // alerts 25

与任何其他Javascript对象一样,您也可以通过以下方式访问它:

fc_json['custom_fields']['affiliateID'] // Returns "25"