WebAPIを使って郵便番号から住所文字列を取得

; ; zipcloud(郵便番号データ配信サービス)を使って、 ; 郵便番号から住所文字列を取得するサンプル […]

; ; zipcloud(郵便番号データ配信サービス)を使って、 ; 郵便番号から住所文字列を取得するサンプル […]

;
; zipcloud便使
; 便
;
#include "hspinet.as"
#include "encode.as"
#include "hspinet.as"
netinit
if stat : dialog "" : end
; URL
neturl "http://zipcloud.ibsnet.co.jp/api/"
;
; GETCGI
; zipcode 便
; callback
; limit
yubin = "100-0013" ;
; yubin = "0790177" ; /
netrequest_get "search?zipcode=" + yubin
mes "DOWNLOAD "
*main
;
netexec res
if res > 0 : goto *comp
if res < 0 : goto *bad
await 50
goto *main
*bad
;
neterror estr
mes "ERROR "+estr
stop
*comp
;
mes "DOWNLOAD "
netgetv buf
; UTF8 -> Shift-JIS
buf_sjis = utf8n2sjis( buf )
; LF -> CL+LF
; JSON
CL = ""
LF = ""
poke CL, 0, $0D
poke LF, 0, $0A
strrep buf_sjis, LF, CL+LF
mesbox buf_sjis,640,200,1
; JSON
;
; status 200
; message
; results --- ---
; zipcode 便 7便
; prefcode JIS X 0401 2
; address1
; address2
; address3
; kana1
; kana2
; kana3
;
;
; 400
; 500 API
jsonopen ptJson, buf_sjis
jsongetobj ptJson_results, "results", ptJson
; address
jsonnext ptJson_results_c, ptJson_results, 2
while( ptJson_results_c != 0 )
jsongets ad1 ,"address1", ptJson_results_c
jsongets ad2 ,"address2", ptJson_results_c
jsongets ad3 ,"address3", ptJson_results_c
mes "" + ad1 + ad2 + ad3
jsonnext ptJson_results_c, ptJson_results_c, 0
wend
; status
jsongeti st, "status", ptJson
; mes "(" + stat + ") " + st
if st = 200 : mes ""
if st = 400 : mes ""
if st = 500 : mes "API"
jsonclose
stop
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX