Skip to content

Instantly share code, notes, and snippets.

@Pittan
Created March 14, 2017 13:07
Show Gist options
  • Save Pittan/be9c22593f4a98a57ae8e2637d8d8d95 to your computer and use it in GitHub Desktop.
Save Pittan/be9c22593f4a98a57ae8e2637d8d8d95 to your computer and use it in GitHub Desktop.
Convert
<?php
// AngularでCORSのエラー出て面倒なので(ほんとはちゃんとやりたいけど)
header("Access-Control-Allow-Origin: *");
// IPアドレスさすがにアレなので、自分で見つけてきてね
$url = "http://XXX.XXX.XXX.XXX:XXXX/dataspider/trigger/path";
$json = file_get_contents($url);
// 最終的に返すデータ
$response = array();
$twres = array();
$webres = array();
foreach (json_decode($json, true) as $key => $val) {
$tmpElements = array();
foreach ($val as $k => $v) {
if ($k == "twitterContent" || $k == "webContent") {
//この2つだけJSONをパースして改めてオブジェクトとして返す
$tmpElements[$k] = json_decode($v);
} else {
$tmpElements[$k] = $v;
}
}
if ($tmpElements['twitterContent']) array_push($twres, $tmpElements);
if ($tmpElements['webContent']) array_push($webres, $tmpElements);
}
$i = 0;
for ($i = 0; $i <30 ; $i++) {
if ($i % 2 == 0) {
$el = array_shift ($webres);
if ($el) array_push($response, $el);
} else {
$el = array_shift ($twres);
if ($el) array_push($response, $el);
}
}
echo json_encode($response, JSON_UNESCAPED_UNICODE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment