0

I have a multilevel JSON result, how would I go about it in PHP to get a certain value, like, the order_id for instance, here is the json result.

   {
   "metaField":[
      {
         "name":"order_id",
         "autoEntered":1,
         "global":0,
         "maxRepeat":1,
         "resultType":"number"
      },
      {
         "name":"fm_id",
         "autoEntered":0,
         "global":0,
         "maxRepeat":1,
         "resultType":"number"
      },
      {
         "name":"Name",
         "autoEntered":0,
         "global":0,
         "maxRepeat":1,
         "resultType":"text"
      },
      {
         "name":"Surname",
         "autoEntered":0,
         "global":0,
         "maxRepeat":1,
         "resultType":"text"
      },
      {
         "name":"Lever",
         "autoEntered":0,
         "global":0,
         "maxRepeat":1,
         "resultType":"number"
      },
      {
         "name":"othert",
         "autoEntered":0,
         "global":0,
         "maxRepeat":1,
         "resultType":"text"
      }
   ],
   "meta":[
      {
         "recordID":"53",
         "href":"\/RESTfm\/FMServer_Test2\/layout\/resttest\/53.json"
      }
   ],
   "data":[
      {
         "order_id":"100053",
         "fm_id":"53",
         "Name":"Christo",
         "Surname":"Alberts",
         "Lever":"5",
         "othert":"WowWow"
      }
   ],
   "info":{
      "X-RESTfm-Version":"4.0.4\/UNKNOWN",
      "X-RESTfm-Protocol":"5",
      "X-RESTfm-Status":201,
      "X-RESTfm-Reason":"Created",
      "X-RESTfm-Method":"POST",
      "X-RESTfm-Profile":"109ms 2.5M 128M",
      "X-RESTfm-PHP-memory_limit":"128M",
      "X-RESTfm-PHP-post_max_size":"8M"
   }
}
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208

1 Answers1

0

Decode json

 $json_array = json_decode($json);
 $metaField = $json_array->metaField;
 for($i=0; $i<count($metaField); $i++)
 {
   echo $metaField[$i]->name;
 }
Komal
  • 2,716
  • 3
  • 24
  • 32