このようなJSONファイルを最初から作成する必要があります
{
"results": {
"course": "CC167",
"books": {
"book": [
{
"-id": "585457",
"-title": "Beginning XNA 20 game programming : from novice to professional",
"-isbn": "1590599241",
"-borrowedcount": "16"
},
{
"-id": "325421",
"-title": "Red Hat Linux 6",
"-isbn": "0201354373",
"-borrowedcount": "17"
},
{
"-id": "424317",
"-title": "Beginner's guide to darkBASIC game programming",
"-isbn": "1592000096",
"-borrowedcount": "46"
},
{
"-id": "437390",
"-title": "Objects first with Java : a practical introduction using BlueJ",
"-isbn": "0131249339",
"-borrowedcount": "89"
},
{
"-id": "511094",
"-title": "Objects first with Java : a practical introduction using BlueJ",
"-isbn": "2006044765",
"-borrowedcount": "169"
}
]
}
}
}
これは私が作成したPHPなので、大きなジャンプではないことを願っていますが、PHPでJSONオブジェクトをゼロから作成する方法については何もできません。 JSON 自身
$y = 1;
$json = "{";
$json = $json . "\"results\": {";
$json = $json . "\"course\": \"$cc\",";
$json = $json . "\"books\": {";
$json = $json . "\"book\": [";
foreach ($my_array as $counter => $bc) {
$json = $json . "{";
$json = $json . "\"-id\": \"$id[$counter]\",";
$json = $json . "\"-title\": \"$title[$counter]\",";
$json = $json . "\"-isbn\": \"$isbn[$counter]\",";
$json = $json . "\"-borrowedcount\": \"$borrowedcount[$counter]\"";
$json = $json . "}";
if ($x != $y) $json = $json . ",";
$json = $json . "";
$y++;
}
$json = $json . "]";
$json = $json . "}";
$json = $json . "}";
$json = $json . "}";
echo $json;