3

I have a json string. I want to get the values from that string using the field name. Please help me to get this. This is my json string format.

[
    {
        "FLD_ID": 1,
        "FLD_DATE": "17-02-2014 04:57:19 PM"
        "FLD_USER_NAME": "DAFEDA",
        "FLD_USER_EMAIL": "[email protected]",
        "FLD_USER_PASS": "test"
    }
]
2
  • 1
    What have you tried. Also, your string is invalid JSON; seems to be missing a comma Commented Mar 4, 2014 at 3:57
  • You can find answers here: stackoverflow.com/questions/6487167/… Commented Mar 4, 2014 at 3:59

2 Answers 2

5

I'm not really sure what the question is but how about

// assuming str is your JSON string

var obj = JSON.parse(str); // parse the string into an object

var firstObj = obj[0]; // get the first (and only) object out of the array

var fld_id = firstObj.FLD_ID; // you can access properties by name like this

var fld_date = firstObj['FLD_DATE']; // or like this
Sign up to request clarification or add additional context in comments.

Comments

1

your JSON was invalid. I fixed it for you.

[{"FLD_ID":1,"FLD_DATE":"17-02-2014 04:57:19 PM", "FLD_USER_NAME":"DAFEDA","FLD_USER_EMAIL":"[email protected]","FLD_USER_PASS":"test"}]

here's a working example of how to alert the FLD_ID

<script>
var json = [{"FLD_ID":1,"FLD_DATE":"17-02-2014 04:57:19 PM", "FLD_USER_NAME":"DAFEDA","FLD_USER_EMAIL":"[email protected]","FLD_USER_PASS":"test"}];
alert(json[0].FLD_ID);
</script>

By the way, this is an array with 1 JSON object, which is why you must reference the index, 0 in this case.

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.