我是编程新手。当我需要发送一个json视图时,我有一个任务:
{
"code" : 200,
"error" : 0,
"data" : {
"sLogo" : "http://test.com/images/logo.png",
"aWinners": [
{
"sName": "name"
}
]
}
}
我现在如何管理数据,但我不了解如何管理code
和error
。你能帮我一下吗? Thx提前和抱歉我的英语。我的想法是,我需要发送这个json的视图,但我不明白mus包含code
答案 0 :(得分:0)
您可以使用json_decode()获取代码和错误值。
$json = '{"code" : 200,"error" : 0,"data" : {"sLogo" : "http://test.com/images/logo.png","aWinners": [{"sName": "name"}]}}';
$arr = json_decode($json, TRUE);
echo $arr['code'];
echo $arr['error'];
答案 1 :(得分:0)
Note: Just pass the json as string from controller to your view and then decode your data in the view as per your requirement.
In Controller
<?php
$json = '{"code" : 200,"error" : 0,"data" : {"sLogo" : "http://test.com/images/logo.png","aWinners": [{"sName": "name"}]}}';
?>
In View
<?php
$arr = json_decode($json, TRUE);
$code= $arr['code'];
$error= $arr['error'];
?>