我有一个来自weather.com的json文件。如何从“今天”列中获取数据并通过php显示。
public Record insertData(
Configuration configuration, Table<? extends Record> table, Map<TableField<? extends Record, ?>, Object> map
)
{
return DSL.using(configuration)
.insertInto(table)
.set(map)
.returning()
.fetchOne();
}
答案 0 :(得分:0)
您可以使用array_column仅获取值。
然后,如果您使用array_combine和array_keys,则也可以获取密钥。
$arr = json_decode($json, true);
$todayvalues = array_column($arr["vt1dailyforecast"]["day"], 0);
$todaykeys = array_keys($arr["vt1dailyforecast"]["day"]);
$today = array_combine($todaykeys, $todayvalues);
输出
array(20) {
["dayPartName"]=>
string(5) "Today"
["precipPct"]=>
int(10)
["precipAmt"]=>
float(0)
["precipType"]=>
string(4) "rain"
["temperature"]=>
int(96)
["uvIndex"]=>
int(10)
["uvDescription"]=>
string(9) "Very High"
["icon"]=>
int(30)
["iconExtended"]=>
int(3000)
["phrase"]=>
string(13) "Partly Cloudy"
["narrative"]=>
string(50) "Partly cloudy. High 96F. Winds light and variable."
["cloudPct"]=>
int(36)
["windDirCompass"]=>
string(1) "S"
["windDirDegrees"]=>
int(177)
["windSpeed"]=>
int(5)
["humidityPct"]=>
int(57)
["qualifier"]=>
NULL
["snowRange"]=>
string(0) ""
["thunderEnum"]=>
int(0)
["thunderEnumPhrase"]=>
string(10) "No thunder"
}