Created
May 27, 2016 00:33
-
-
Save steelydylan/e742b4f88f7856bbf95bb003b3fd3a5e to your computer and use it in GitHub Desktop.
1次元配列のJSONを出力するためのPHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ACMS_User_GET_Json extends ACMS_GET | |
{ | |
function get() | |
{ | |
$id = $this->identifier; | |
$json = file_get_contents($id); | |
$arr = json_decode($json); | |
$Tpl = new Template($this->tpl, new ACMS_Corrector()); | |
if($arr){ | |
$count = count($arr); | |
for($i = 0 ; $i < $count; $i++){ | |
$obj = $arr[$i]; | |
$item = array(); | |
foreach ($obj as $key => $value){ | |
$item[$key] = $value; | |
} | |
$Tpl->add(array('json:loop'),$item); | |
} | |
} | |
$Tpl->add(null,array("count"=>$count)); | |
return $Tpl->get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<!-- BEGIN_MODULE Json id="http://example.com/api/~test.json" --><!-- END_MODULE Json -->