0

I have a json string like the below format. I would like to get the Table1.ActualDate value. How can i get this using jquery.

{
    "Table": [
        {
            "DisplayVoucherNumber": "A101239Z",
            "ActualDate": "08/07/2013",
            "AccountName": "shyamal",
            "Pcs": "50",
            "Weight": "500.000"
        }
    ],
    "Table1": [
        {
            "DisplayVoucherNumber": "R101249B",
            "ActualDate": "11/07/2013",
            "AccountName": "vipul",
            "NetWeight": "90.000",
            "Weight": "80.000",
            "Difference": "10.000"
        },
        {
            "DisplayVoucherNumber": "R101249B",
            "ActualDate": "11/07/2013",
            "AccountName": "vipul",
            "NetWeight": "500.000",
            "Weight": "100.000",
            "Difference": "400.000"
        }
    ]
}
4
  • there are 2 ActualDate values... which one Commented Mar 6, 2014 at 6:14
  • if data refers to this object then data.Table1[0].ActualDate.. Commented Mar 6, 2014 at 6:14
  • and data.Table1[1].ActualDate Commented Mar 6, 2014 at 6:16
  • var jObj = JSON.parse(jsonString);for(i=0;i<jObj.Table1.length;i++) { console.log(jObj.Table1[i].ActualDate); } Commented Mar 6, 2014 at 6:18

6 Answers 6

1

You have to parse that string to get a valid JSON object.

Try,

var xObj = JSON.parse(xString);
console.log(xObj.Table1[0].ActualDate);

where xString is the string variable contains your JSON string.

Sign up to request clarification or add additional context in comments.

Comments

0

If it is a string, you should make it as a json object using

var data= jQuery.parseJSON(data); 

After that can use it like.

 alert(data.Table1[0].ActualDate);

If it is an abject already, you dont have to use the jQuery.parseJSON() method

Comments

0

Since your Table1 array may grow, I would suggest you to go for iteration like

var tab = JSON.parse("you object");
for (i = 0; i < tab["Table1"].length; i++) {
    console.log(tab["Table1"][i].AccountName);
}

Comments

0
var jObj = JSON.parse(jsonString); // Converts the string to JSON object

if(jObj !== undefined && jObj.Table1 !== undefined) {
    for (i = 0; i < jObj.Table1.length; i++) {
        console.log(jObj.Table1[i].ActualDate); 
    }
}

Comments

0

You can use:

$.each(json.Table1, function(x, contents) {
    alert(contents.ActualDate);
});

Fiddle Demo

Comments

0
        var json = {
            "Table": [
                {
                    "DisplayVoucherNumber": "A101239Z",
                    "ActualDate": "08/07/2013",
                    "AccountName": "shyamal",
                    "Pcs": "50",
                    "Weight": "500.000"
                }
            ],
            "Table1": [
                {
                    "DisplayVoucherNumber": "R101249B",
                    "ActualDate": "11/07/2013",
                    "AccountName": "vipul",
                    "NetWeight": "90.000",
                    "Weight": "80.000",
                    "Difference": "10.000"
                },
                {
                    "DisplayVoucherNumber": "R101249B",
                    "ActualDate": "13/08/2012",
                    "AccountName": "vipul",
                    "NetWeight": "500.000",
                    "Weight": "100.000",
                    "Difference": "400.000"
                }
            ]
        };


        for(var i=0; i<json.Table1.length; ++i) {
            alert(json.Table1[i].ActualDate)
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.