$params[] = 'cols=' . urlencode(json_encode($columns)); $params[] = 'meta=' . urlencode(json_encode($meta)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POSTFIELDS, implode('&', $params)); $content = curl_exec($curl); $obj = json_decode($content); if ($obj->error) { //throw new Exception($obj->message); } } public function getContent($url) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $content = curl_exec($curl); curl_close($curl); return $content; } } $i = new Importer(); $data_hk = json_decode($i->getContent('http://gazetteer.hk/locale/zh-HK/generated_ns-translation.json')); $data_us = json_decode($i->getContent('http://gazetteer.hk/locale/en-US/generated_ns-translation.json')); $data_cn = json_decode($i->getContent('http://gazetteer.hk/locale/zh-CN/generated_ns-translation.json')); foreach ($data_hk->district as $id => $name) { $i->insertData("/ronnywang/香港行政區劃-分區", array(strtoupper($id), $name, $data_cn->district->{$id}, $data_us->district->{$id}), array(0)); } foreach ($data_hk->area as $id => $name) { $i->insertData("/ronnywang/香港行政區劃-選區", array(strtoupper($id), substr($id, 1), strtoupper($id[0]), $name, $data_cn->area->{$id}, $data_us->area->{$id}), array(0)); } $i->commitData();