json - php json_decode skippes some keys -


here json decode:

{"somearray":[     {      "id":71398,      "prices":{          "simple":270,          "vip":300,          "sofa":540,          "extra":320          }     },     {      "id":71399,      "prices":{          "simple":190,          "vip":190,          "sofa":380          }      },     {...} ]} 

note: items have price "extra", , not have it.

json valid according online json validators. when try decode in php

json_decode($json, true); 

(true - retrieve data associative array.) key "extra" ignored json_decode.

so if var_dump() decoded resul or try $item['prices']['extra'] there no "extra" key-value in it.

why???

this works fine when json valid:

<?php $json = '{"somearray":[     {      "id":71398,      "prices":{          "simple":270,          "vip":300,          "sofa":540,          "extra":320'. // there comma here.          '}     },     {      "id":71399,      "prices":{          "simple":190,          "vip":190,          "sofa":380          }      } ]}';  print_r(json_decode($json)); ?> 

output:

[somearray] => array         (             [0] => stdclass object                 (                     [id] => 71398                     [prices] => stdclass object                         (                             [simple] => 270                             [vip] => 300                             [sofa] => 540                             [extra] => 320                         )                  )              [1] => stdclass object                 (                     [id] => 71399                     [prices] => stdclass object                         (                             [simple] => 190                             [vip] => 190                             [sofa] => 380                         )                  )          ) 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -