您好我有這是由下面的代碼生成一個數組結果:如何訪問這個數組
//Get House Sales Date
// Create a stream
$username = "test";
$password = "test";
$remote_url2 = "https://www.streetcheck.co.uk/api/v1/postcode/".$cleanpostcode."/saleprices";
$opts2 = array( 'http'=>array( 'method'=>"GET", 'header' => "Authorization: Basic " . base64_encode("$username:$password")));
$context2 = stream_context_create($opts2);
//Open the file using the HTTP headers set above
$json2 = json_decode(file_get_contents($remote_url2, false, $context2));
//If Valid Results Returned
if($json2->message="ok")
{
print_r($json2);
查詢的結果可以看出here。
我需要能夠做的是爲每個結果,把值插入到另一個表,到目前爲止我在看是這樣的:
foreach ($json2->result->sales as $item1)
{
$pricepaid = $json2->result->sales->pricePaidGBP;
$propertytype = $json2->result->sales->propertyType;
$holding = $json2->result->sales->holding;
$nameornumber = $json2->result->sales->nameOrNumber;
$fulllocation = $json2->result->sales->fullLocation;
$dateoftransfer = $json2->result->sales->dateOfTransfer;
但結果回來爲空,我在做什麼錯了,請>
可能想'$ pricepade = $ item1-> pricePaidGBP'。否則爲什麼麻煩循環「 - > result-> sales」,然後完全忽略循環爲您生成的變量? – 2014-11-24 16:55:18