Skip to content

Instantly share code, notes, and snippets.

@steelydylan
Created May 27, 2016 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steelydylan/e742b4f88f7856bbf95bb003b3fd3a5e to your computer and use it in GitHub Desktop.
Save steelydylan/e742b4f88f7856bbf95bb003b3fd3a5e to your computer and use it in GitHub Desktop.
1次元配列のJSONを出力するためのPHP
<?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();
}
}
@steelydylan
Copy link
Author

steelydylan commented May 31, 2016

<!-- BEGIN_MODULE Json id="http://example.com/api/~test.json" --><!-- END_MODULE Json -->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment