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 );
精彩评论