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": "test@gmail.com",
        "FLD_USER_PASS": "test"
    }
]
code-jaff
  • 9,230
  • 4
  • 35
  • 56
user3085540
  • 275
  • 3
  • 12
  • 27
  • 1
    What have you tried. Also, your string is invalid JSON; seems to be missing a comma – Phil Mar 04 '14 at 03:57
  • You can find answers here: http://stackoverflow.com/questions/6487167/deserialize-from-json-to-javascript-object – Leo Mar 04 '14 at 03:59

2 Answers2

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
Phil
  • 157,677
  • 23
  • 242
  • 245
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":"test@gmail.com","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":"test@gmail.com","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.

Zack
  • 1,615
  • 18
  • 26