【发布时间】:2016-11-28 10:33:03
【问题描述】:
这是我的代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.openweathermap.org/data/2.5/weather?q=".$location.",de&lang=de&APPID=abc");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch); //JSON string
curl_close($ch);
//json_decode($output);
//serialize($output);
$table_name = $wpdb->prefix . 'dmd_weather';
$wpdb->insert(
$table_name,
array(
'time' => current_time( 'mysql' ),
'type' => 'wetter',
'key' => $location, //<- normal string
'value' => $output //<- json string
)
);
我无法使用上面的查询插入数据。
如果我将 var $output 更改为 $output = 1 ,它会完美运行。但不是 json 字符串。
用wordpress将json字符串插入数据库有技巧吗?
【问题讨论】: