tags:

views:

344

answers:

2

Hi everybody,

I think this is a simple issue I just haven't worked with JSON like this before.

Very simply, I have a JSON object:

fc_json = {
    "product_count": 1,
"total_price": 199.95,
"total_weight": 1,
"session_id": "26e8og4ldmlunj84uqf04l8l25",
    "custom_fields":{
        "affiliateID":"25"
    },
"messages":{
 "errors":[],
 "warnings":[],
 "info":[]
}
};

and I want to extract just the variable of affiliateID using jQuery. Is there a simple way to do this? I really have no idea.

+5  A: 

You don't need jQuery to access a JSON object. In fact, a JSON object IS a JavaScript object.

You should be able to do

alert(fc_json.custom_fields.affiliateID) // alerts 25
SolutionYogi
oh right. Its THAT easy! thanks Yogi
cosmicbdog
+1  A: 

Just like any other Javascript object, you could also access it with:

fc_json['custom_fields']['affiliateID'] // Returns "25"
Sinan Taifour
Thanks STAii. appreciate it..
cosmicbdog