0

I have a JSON object that I get from a PHP script using the JSON_ENCODE method.

My JSON:

[{"0":"1","field_name1":"1","1":"fieldValue1","field_name2":"fieldValue2","2":"0","field_name3":"fieldValue3","3":"1","field_name4":"fieldValue4"},
{"0":"11","field_name1":"1","1":"fieldValue1","field_name2":"fieldValue2","2":"0","field_name3":"fieldValue3","3":"1","field_name4":"fieldValue4"}]

I want to be able to access my field names and my field values via a loop for loop or via an each function , I can use JavaScript or JQuery, but I don't know how to do it, can you help me?

EDIT : I already tried the answer on this question : Safely turning a JSON string into an object

it gives me this output :

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Community
  • 1
  • 1
samouray
  • 578
  • 1
  • 11
  • 26
  • have you parse your json? –  Feb 11 '16 at 10:46
  • You need to parse with the function "$.parseJSON" (jQuery) to have an array of Object (named obj for example). After you just need to iterate on this array (for or foreach loop) and access data like an array. For example with a for loop : obj[i]["field_name2"]. – Berserk Feb 11 '16 at 10:55
  • 1
    "it gives me this output" — That's the expected result of converting a JSON array or objects into a JavaScript array of objects and then converting to a plain string. – Quentin Feb 11 '16 at 10:56
  • show what you tried or make a fiddle –  Feb 11 '16 at 11:00

0 Answers0