如何使用jQuery访问一些JSON?

wil*_*fun 3 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":[],
    "warnings":[],
    "info":[]
}
};
Run Code Online (Sandbox Code Playgroud)

我想用jQuery提取affiliateID的变量.有一个简单的方法吗?我真的不知道.

Sol*_*ogi 11

您不需要jQuery来访问JSON对象.实际上,JSON对象是一个JavaScript对象.

你应该能做到的

alert(fc_json.custom_fields.affiliateID) // alerts 25
Run Code Online (Sandbox Code Playgroud)