开发者

JSON format in PHP

{
  "require开发者_StackOverflow社区d_items": [{
      "filename": "abcd",
      "no": "3"
    },
    {
      "filename": "abc",
      "no": "2"
    }
  ]
}

I am not getting the code of the JSON format in PHP - I want to insert the filename and no through a loop.


Pass the JSON to json_decode and you'll end up with an regular PHP data structure you can operate on. Use var_dump to take a look at it. When you're done manipulating it, turn it back into JSON with json_encode

I don't know if it's typos on your part, but the format you pasted isn't valid JSON.


If you're asking how to generate the above JSON code in PHP, do something like this:

$object->required_items = array();

for( ... your loop here ... )
{
    $item->filename = 'filename';
    $item->no = 1;
    $object->required_items[] = $item;
}

$json = json_encode( $object );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜