如何将 stdClass 对象的名称导入数据库?
JSON 对象包含:
[items] => stdClass Object
(
[bigitems] => stdClass Object
(
[nameitem1] => stdClass Object
(
[height] => 100
[width] => 137
)
[nameitem2] => stdClass Object
(
[height] => 506
[width] => 678
)
[nameitem3] => stdClass Object
(
[height] => 330
[width] => 845
)
[nameitem3] => stdClass Object
(
[height] => 793
[width] => 788
)
)
)
我只想将值 nameitem1 - nameitem4 存储到数据库中
Nameitems 是例如 - box,case - 不同的词没有数字范围 Bigitems 是一个 NUMBER
[items] => stdClass Object
(
[4856985254] => stdClass Object
(
[box] => stdClass Object
(
[height] => 100
[width] => 137
)
[case] => stdClass Object
(
[height] => 506
[width] => 678
)
[paper] => stdClass Object
(
[height] => 330
[width] => 845
)
)
对于此操作,我尝试使用此脚本。脚本工作但缺少商店部分
function wwwResponse($url, $isUrl = true)
{
if ($isUrl && !ini_get('allow_url_fopen')) {
throw new Exception('allow_url_fopen = Off');
}
$content = file_get_contents($url);
if ($isUrl) {
$status_code = substr($http_response_header[0], 9, 3);
if ($status_code != 200) {
throw new Exception('Got status code ' . $status_code . ' expected 200');
}
}
$json = json_decode($content);
if (!$json) {
throw new Exception('Response contained an invalid JSON response');
}
if ($json->status != 'ok') {
throw new Exception($json->status_code);
}
return $json;
}
// --------------------------DB-------------------------------
mysql_connect("localhost", "baze", "xxxxxxx");
mysql_select_db("baze");
//------------------------------------------------------------
try {
$json = wwwResponse($url);
print_r ($json);
}
catch (Exception $e) {
echo $e->getMessage();
}
echo "<pre>\n";
}
感谢帮助