0

Have JSON as $json

I convert it to an array using:

$myarray = json_decode($json, true);

print_r($myarray) gives this:

Array (
[0] => Array
( [ProjectId] => 2765297 [ProjectName] => Acme Example) 
[1] => Array
( [ProjectId] => 4526847 [ProjectName] => Smiths Example)
)

When I try to use foreach like this:

foreach ($results as $key => $result) {
echo $result[ProjectName] . ' Project ID:' . $result[ProjectID];
}

I get the ProjectName but not the ProjectID.

When I look as the original JSON ($json), the ProjectID appears to be unquoted like an integer.

[
   {
        "ProjectId":2765297,
        "ProjectName":"Acme Example"
    },
    {
        "ProjectId":4526847,
        "ProjectName":"Smiths Example"
    }
]

When I try to convert to a string or run checks to see if it is an integer, it is ether blank or null.

Justin
  • 31
  • 5
  • 1) Use quotes for your keys 2) `ProjectID` != `ProjectId` – Rizier123 Jan 11 '17 at 16:14
  • In you json you have ProjectId but you are trying to access ProjectID (case sensitive), maybe is that, and I recommend you to put the array key between apostrphes like $result["ProjectID"] – alvaropgl Jan 11 '17 at 16:15
  • Rizier123, it is overwhelmingly frustrating that I do not heed Occam's razor. It was my lack of attention to case that was the problem. Thanks for your quick response. – Justin Jan 11 '17 at 18:01

0 Answers0