0

Following below is the json data which i am sending to php controller by using ajax

[  
   {  
      "First":"A,b"
   },
   {  
      "Second":""
   },
   {  
      "Third":""
   },
   {  
      "Fourth":""
   },
   {  
      "Fifth":""
   },
   {  
      "Sixth":""
   },
   {  
      "Seventh":""
   },
   {  
      "Eight":""
   },
   {  
      "Ninth":""
   },
   {  
      "Tenth":""
   }
]

how can i read values and stored it in php variable or use loop with above json string

VLAZ
  • 22,934
  • 9
  • 44
  • 60
Rahim Shaikh
  • 3
  • 1
  • 6

2 Answers2

0

You need to decode your json string by using json_decode() than you can use foreach() loop.

print_r(json_decode($jsonString,TRUE)); // will return response in an array

print_r(json_decode($jsonString)); // will return response in an object

And you can read the data as:

$decoded = json_decode($jsonString,TRUE);

foreach( $decoded as $key => $value ){
    // print values
    // print key
}
devpro
  • 16,074
  • 3
  • 26
  • 39
0

Try to use PHP built in function json_decode

http://www.php.net/manual/en/function.json-decode.php

Then access it like an array

Bartosz Gajda
  • 145
  • 1
  • 9