我想从json数组中获取两个变量的值。数组变成ajax,然后解码并“保存”到$jsonarray
。然后我尝试从数组中获取volume
和symbol
变量并将它们插入到我的数据库中。我不明白这$jsonarray->result->{"quote"}->symbol
的语法,并尝试过任何时候它的权利,但错误不会消失。获取多维json数组的值
这就是我的数组:
{"query":{"count":1,"created":"2016-02-15T15:11:47Z","lang":"de-DE","results":{"quote":{"symbol":"ZN","Ask":"2.05","Bid":"1.78","Volume":"13214","PercentChange":"+0.56%"}}}}
有关PHP件:
$jsonString = $_POST['mydata'];
$jsonarray = json_decode($jsonString[0]['query']);
if ($stmt = $mysqli->prepare('INSERT INTO volume (stocksymbol, volume, time) VALUES (?, ?, now())')) {
/* bind parameters for markers */
$stmt->bind_param("si", $jsonarray->result->{"quote"}->symbol, $jsonarray->result->{"quote"}->Volume);
/* execute query */
$stmt->execute();
/* close statement */
$stmt->close();
}
'$ jsonarray-> result->报价 - > symbol' – fusion3k
您应该仔细阅读手册,了解如何调用bind_param':http://php.net/manual/en/mysqli-stmt.bind-param.php – deceze
现在您已经修复了问题的原因......是否还有问题...?! – deceze