2013-01-10 33 views
0

我有一个qeustion为你,我有一个JSON Api给我一些信息,其中一些是不是有用的。Joomla json输出组件2.5从控制器查看

用下面的代码行我可以调用所有信息,并写入我的观点:

$url = 'http://apisurl.com/prequalify/json/'.$postcode.'/'.$huisnummer.''; 
    $content = file_get_contents($url); 
    $json = json_decode($content); 

把它寄给你的观点:

$view->assignRef('info', $content); 

这是我的正常的PHP代码:

foreach ($json['enduserinfo'] as $item) { 
     echo " Postcode: {$item['zipcode']} 
     <br /> Huisnummer: {$item['housenr']} 
     <br /> Straatnaam: {$item['street']} 
     <br /> Woonplaats: {$item['city']} 
     <br /> Centrale: {$item['centrale']} 
     <br /> Toegangspunt: {$item['access-area']} 
     <br /> Isra: {$item['isra']}"; 
    } 

如何在Joomla中获得相同的结果?

对我来说,真正的问题是我不需要所有的信息,我想设置一些变量来存储正确的数据。并且只发送它们到我的视图。现在结果是我的页面中只有一个完整的JSON文件。

在我的正常php脚本中,Joomla的extern工作正常。 Joomla是否有特殊的方式来做到这一点?

请帮助

+0

为什么你在assignref中设置$内容,你只需要将它分析并将需要的数据集作为assignref中的一个数组。 –

+0

你在视图中使用jquery吗? –

+0

@mamdouhalramadan我没有使用JQuery。 – JSkirMan

回答

0

在你的控制器,你应该做到以下几点:

$myJson = json_decode($content, true); // will make it as associative array 
$theIndexIwantToSendToTheView = $myJson['enduserinfo']; 
//send to view the variable $theIndexIwantToSendToTheView 

现在你可以使用变量$myJson

这将解决你的问题处理JSON