Click here to Skip to main content
16,018,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to fetch the values of prepaid and cod from the below JSON in jquery how can I do it?

JavaScript
{
    "delivery_codes": [
        {
            "postal_code": {
                "pin": 400067,
                "district": "Mumbai",
                "max_amount": 0,
                "pre_paid": "Y",
                "cash": "Y",
                "pickup": "Y",
                "repl": "Y",
                "cod": "Y",
                "sort_code": "MUM/MAL",
                "is_oda": "N",
                "state_code": "MH"
            }
        }
    ]
}
Posted

 
Share this answer
 
http://www.w3schools.com/json/json_eval.asp[^]

<script type="text/javascript">
    // if you have the raw json
    var jA = {
        "delivery_codes": [
            {
                "postal_code": {
                    "pin": 400067,
                    "district": "Mumbai",
                    "max_amount": 0,
                    "pre_paid": "Y",
                    "cash": "Y",
                    "pickup": "Y",
                    "repl": "Y",
                    "cod": "Y",
                    "sort_code": "MUM/MAL",
                    "is_oda": "N",
                    "state_code": "MH"
                }
            }
        ]
    };

    alert("Prepaid = " + jA.delivery_codes[0].postal_code.pre_paid);
    alert("COD = " + jA.delivery_codes[0].postal_code.cod);

    // if you have the json as a string
    var json = '{"delivery_codes": [{"postal_code": {"pin": 400067,"district": "Mumbai","max_amount": 0,"pre_paid": "Y","cash": "Y","pickup": "Y","repl": "Y","cod": "Y","sort_code": "MUM/MAL","is_oda": "N","state_code": "MH"}}]}';
    var jB = JSON.parse(json);

    alert("Prepaid = " + jB.delivery_codes[0].postal_code.pre_paid);
    alert("COD = " + jB.delivery_codes[0].postal_code.cod);

</script>
 
Share this answer
 
v2
Comments
bhavikadb 23-Sep-15 7:38am    
can u please give me the code for it I am very new to json
F-ES Sitecore 23-Sep-15 8:21am    
I updated the answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900