2013-03-11 76 views
-1

我有一个包含来自页面的Facebook数据的JSON文件。我需要的是根据JSON文件创建tablecheckbox条目。我正在使用php sdkjavascript sdkHTML动态创建表单条目?

我这样想的一种方法的:

<?php 
$array_of_decoded=json_decode("$myjson",true); 
for($i=0;$array_of_decoded(i);i++) 
{?> 
// create new entry in html form with the following propreties: 
<input type="checkbox" name="<?php array_of_decoded(i)['name']?>" 
value="<?php array_of_decoded(i)['id']?>"><?php array_of_decoded(i)['name']?<br> 
<?php 
//... 
}?> 

我的JSON文件具有类似的条目下列内容:

{"category":"Musician\/band","name":"Yann Tiersen (official)","id":"18359161762"} 

我在这一个新手,和上面的代码可能是错的,我只是现场写的,没有测试。有没有人有一个想法如何创建新的条目?上面的代码是否显示了如何正确解码json?

回答

1

你可以把它用“foreach”:

<?php 
foreach(json_decode("$myjson",true) as $element) {?> 
    <input type="checkbox" name="<?php echo $element['name']?>" value="<?php echo $element['id']?>"><?php echo $element['name']?><br> 
<?php }?> 

当然,这必须放置在视图页!

+0

谢谢,刚开始实施它 – 2013-03-11 10:09:30