Here is the response that I am receiving.
{
"StartTime":"2016-01-15T03:22:33.109787-05:00",
"EndTime":"2016-01-15T03:22:34.2504378-05:00",
"queryController":{
"TotalRecords":8355,
"PageNumber":1,
"PageSize":8,
"DataFilters":[
],
"PropertyListing":[
{
"EntityName":"Product",
"PropertyName":"IXOneId"
},
{
"EntityName":null,
"PropertyName":"UPC12"
}
],
"EntityName":"QueryController"
},
"Products":[
{
"EntityName":"Product",
"IXOneId":"SNL1080",
"UPC12":"037014000245"
},
{
"EntityName":"Product",
"IXOneId":"SNL1090",
"UPC12":"747599617003"
},
{
"EntityName":"Product",
"IXOneId":"SNL1079",
"UPC12":"024182001822"
},
{
"EntityName":"Product",
"IXOneId":"SNL1102",
"UPC12":"745158300519"
},
{
"EntityName":"Product",
"IXOneId":"SNL1077",
"UPC12":"024182001891"
},
{
"EntityName":"Product",
"IXOneId":"SNL1148",
"UPC12":"039978003645"
},
{
"EntityName":"Product",
"IXOneId":"SNL1110",
"UPC12":"070670005759"
},
{
"EntityName":"Product",
"IXOneId":"SNL1083",
"UPC12":"037014000290"
}
],
"ResponseMessages":null,
"EntityName":"ProductSearchReturn"
}
I want to get the values of IXOneId & UPC12 values of that for all the records and wants to display it on my page. How to get this with help of PHP ? Kinda stuck on that. Help will be appreciated.
Assuming the following variable $string
contains your sample json string.
Decode using json
decode and iterate over the inner Products
array.
$json = json_decode($string);
foreach($json->Products as $product){
print $product->IXOneId . ' ' . $product->UPC12 . PHP_EOL;
}
Will output
SNL1080 037014000245
SNL1090 747599617003
SNL1079 024182001822
SNL1102 745158300519
SNL1077 024182001891
SNL1148 039978003645
SNL1110 070670005759
SNL1083 037014000290
That's a JSON structure. Convert it to array using json_decode
and then loop over it with a while
loop or for
loop to extract the data the way you need it.
Store your data in variable , here in $arr, then use json_decode . Then you can use foreach
$arr=json_decode($arr);
print_r($arr->Products);