Reputation: 1009
{
"required_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.
Upvotes: 1
Views: 2969
Reputation: 10582
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 );
Upvotes: 1
Reputation: 300845
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.
Upvotes: 2