phpjsonparsingstring-parsingphp-parser

Parsing JSON Feed


I have a json feed in a URL that contains following data.

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
[{"ID":1123,"OrderNumber":"1394","ProjectType":"Postcard","Template":"WtlossStudy solo","TemplateURL":"someone.biz/Home/ShowTemplate/283","ShipDate":"2/28/2015","InHomeDate":"3/2/2015","Quantity":"10,000","Price":"$3,000","CallTracking":"0"},{"ID":1123,"OrderNumber":"1413","ProjectType":"Postcard","Template":"WtlossStudy solo","TemplateURL":"","ShipDate":"3/30/2015","InHomeDate":"3/31/2015","Quantity":"5,000","Price":"$1,500","CallTracking":"0"},{"ID":1123,"OrderNumber":"1413","ProjectType":"Postcard","Template":"WtlossStudy solo","TemplateURL":"","ShipDate":"4/13/2015","InHomeDate":"4/14/2015","Quantity":"5,000","Price":"$1,500","CallTracking":"0"}]
</string>

I need to get it and parse it thorough php. But it is giving invalid foreach error with the following code. Can anyone help me on how to show in correctly.

$json = file_get_contents('http://someurl.biz/api/api/1123');

$obj = json_decode($json, true);

foreach($obj as $ob) {
    echo $ob->ID;
}   

Solution

  • Try as

    $json = file_get_contents('http://superiorpostcards.biz/api/api/1123');
    $obj = json_decode($json, true);
    $array = json_decode($obj, true);
    foreach($array as $value){
        echo $value['ID'];
    }