Author Topic: Parser nilai dari web service ektp (hasil JSON)  (Read 273 times)

0 Members and 1 Guest are viewing this topic.

Offline dan2y

  • Senior Member
  • *
  • Posts: 576
Parser nilai dari web service ektp (hasil JSON)
« on: November 13, 2018, 10:46:09 AM »
Selamat siang para suhu fox-id,
saya mau tanya mengenai hasil dari web service, jadi untuk mendapatkan nilai dari web service saya ada buat sintaks php ktp.php, coding sbb:
Code: [Select]
<?php
 
//API Url (alamat url saya samarkan tdk seperti sebenarnya)
$url 'http://xxxxxx:9000/ektp/get_json/namakantor/call_nik';
 
//Initiate cURL.
$ch curl_init($url);
 
//The JSON data.
$jsonData = array(
'nik' => "3671110xxxxxxxxx",
'user_id' => "aku",
'password' => "passwordnya",
'ip_user' => "192.168.1.1"
);
 
//Encode the array into JSON.
$jsonDataEncoded json_encode($jsonData);
 
//Tell cURL that we want to send a POST request.
curl_setopt($chCURLOPT_POST1);
 
//Attach our encoded JSON string to the POST fields.
curl_setopt($chCURLOPT_POSTFIELDS$jsonDataEncoded);
 
//Set the content type to application/json
curl_setopt($chCURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
 
//Execute the request
$result curl_exec($ch);
echo 
$result;
?>



dari http request di atas (saya jalankan ktp.php dari localhost), akan mendapatkan hasil berupa JSON sbb (isi saya samarkan)
Code: [Select]
{"content":[{"NIK":3671110xxxxxxxxx,"NAMA_LGKP":"DANNY XXXXX","KAB_NAME":"KOTA XXX","NO_RW":5,"KEC_NAME":"XXX","JENIS_PKRJN":"KARYAWAN SWASTA","NO_RT":6,"NO_KEL":1001,"ALAMAT":"XXXXXXXXX","NO_KEC":11,"TMPT_LHR":"XXXX","STATUS_KAWIN":"KAWIN","NO_PROP":36,"NAMA_LGKP_IBU":"NAMA IBU","PROP_NAME":"JAKARTA","NO_KAB":71,"KEL_NAME":"XXX","JENIS_KLMIN":"Laki-Laki","TGL_LHR":"1980-01-09"}],"lastPage":true,"numberOfElements":1,"sort":null,"totalElements":1,"firstPage":true,"number":0,"size":1}1

apakah memungkinkan jika buat inputan "Nik", "user id", "password", dan "ip" di form visual foxpro kemudian menampilkan hasil request webservice ke form visual foxpro. ???
saya sudah coba cara mas atmanegara untuk mendapatkan data bpjs tapi tidak berhasil, mohon pencerahannya.. terima kasih

Offline abunuralif

  • Full Member
  • *
  • Posts: 52
Re: Parser nilai dari web service ektp (hasil JSON)
« Reply #1 on: November 14, 2018, 08:02:58 AM »
nyimak.
bahasan bagus

Offline poison

  • Hero Member
  • *
  • Posts: 1.624
  • Poison 4 Women
Re: Parser nilai dari web service ektp (hasil JSON)
« Reply #2 on: November 14, 2018, 12:58:36 PM »
bisa saja...

oh iya, dari pada json, saya lebih suka XML, setelah diterima di FoxPro, tinggal XMLTOCURSOR() data sudah siap pakai...
think BIG to get BIG thing

Offline dan2y

  • Senior Member
  • *
  • Posts: 576
Re: Parser nilai dari web service ektp (hasil JSON)
« Reply #3 on: November 14, 2018, 06:03:02 PM »
bisa saja...

oh iya, dari pada json, saya lebih suka XML, setelah diterima di FoxPro, tinggal XMLTOCURSOR() data sudah siap pakai...

respon dari hasil http request dapetnya JSON om poison, itu tidak bisa di rubah karena sdh dari sononya :)

Offline mochhenry

  • Newbie
  • *
  • Posts: 20
Re: Parser nilai dari web service ektp (hasil JSON)
« Reply #4 on: November 15, 2018, 11:35:52 AM »
googling aja, banyak kok modul agar vfp bisa baca json

Offline Atmanegara

  • Hero Member
  • *
  • Posts: 1.626
  • Berbagi Kerena Peduli
Re: Parser nilai dari web service ektp (hasil JSON)
« Reply #5 on: November 15, 2018, 02:48:04 PM »
saya selalu pakai ini
https://github.com/VFPX/nfJson rekomen deh  :icon_thumleft: :icon_thumleft:
Cara terbaik untuk membuat mimpi Anda menjadi kenyataan adalah dengan bangun dari tidur

Offline dan2y

  • Senior Member
  • *
  • Posts: 576
Re: Parser nilai dari web service ektp (hasil JSON)
« Reply #6 on: November 16, 2018, 10:18:49 AM »
saya selalu pakai ini
https://github.com/VFPX/nfJson rekomen deh  :icon_thumleft: :icon_thumleft:

mas atma saya coba pakai cara mas atma, tapi kenapa responnya kosong ya mas.



ini codingnya
Code: [Select]
SET STEP ON
#define httpstatus_ok 200
#define httpstatus_created 201
#define httpstatus_accepted 202
#define httpstatus_multistatus 207
#define httpstatus_badrequest 400
#define httpstatus_unauthorized 401
#define httpstatus_forbidden 403
#define httpstatus_notfound 404
#define httpstatus_internalservererror 500
clea
nik = 'xxxxxx'
user_id = "xxxxxx"
password = "xxxxx"
ip_user = "192.168.68.1"
lcurl="http://localhost/dukcapil/request6.php"
ohttp = CreateObject("Microsoft.XMLHTTP")
local lcparam
TEXT TO lcparam NOSHOW TEXTMERGE PRETEXT 7
nik=<<nik>>&user_id=<<user_id>>&password=<<password>>&ip_user=<<ip_user>>
ENDTEXT
ohttp.open("POST", lcurl, .F.)
ohttp.setrequestheader('Content-Type', 'application/json;')
ohttp.setrequestheader('Content-length', alltrim(str(len(lcparam))) )
ohttp.setrequestheader('Connection', 'close')
ohttp.send(lcparam)
ohttp.status
lcjson= ohttp.responseText
JSONStart()
oHasil = JSONObject(lcjson)


hasil respon Json dari request6.php
Code: [Select]
{"content":[{"NIK":3671110xxxxxxxxx,"NAMA_LGKP":"DANNY XXXXX","KAB_NAME":"KOTA XXX","NO_RW":5,"KEC_NAME":"XXX","JENIS_PKRJN":"KARYAWAN SWASTA","NO_RT":6,"NO_KEL":1001,"ALAMAT":"XXXXXXXXX","NO_KEC":11,"TMPT_LHR":"XXXX","STATUS_KAWIN":"KAWIN","NO_PROP":36,"NAMA_LGKP_IBU":"NAMA IBU","PROP_NAME":"JAKARTA","NO_KAB":71,"KEL_NAME":"XXX","JENIS_KLMIN":"Laki-Laki","TGL_LHR":"1980-01-09"}],"lastPage":true,"numberOfElements":1,"sort":null,"totalElements":1,"firstPage":true,"number":0,"size":1}1

tdk bisa masukkan gambar  :icon_biggrin:
https://imgur.com/OqNc7H1
« Last Edit: November 16, 2018, 10:29:33 AM by dan2y »

Offline dan2y

  • Senior Member
  • *
  • Posts: 576
Re: Parser nilai dari web service ektp (hasil JSON)
« Reply #7 on: November 16, 2018, 11:10:00 AM »
sudah ada sedikit pencerahan :), munculnya di lcjson bukan di ohasil  ??? ???

« Last Edit: November 16, 2018, 11:12:11 AM by dan2y »

Offline Atmanegara

  • Hero Member
  • *
  • Posts: 1.626
  • Berbagi Kerena Peduli
Re: Parser nilai dari web service ektp (hasil JSON)
« Reply #8 on: November 17, 2018, 09:15:01 PM »
saya selalu pakai ini
https://github.com/VFPX/nfJson rekomen deh  :icon_thumleft: :icon_thumleft:

mas atma saya coba pakai cara mas atma, tapi kenapa responnya kosong ya mas.



ini codingnya
Code: [Select]
SET STEP ON
#define httpstatus_ok 200
#define httpstatus_created 201
#define httpstatus_accepted 202
#define httpstatus_multistatus 207
#define httpstatus_badrequest 400
#define httpstatus_unauthorized 401
#define httpstatus_forbidden 403
#define httpstatus_notfound 404
#define httpstatus_internalservererror 500
clea
nik = 'xxxxxx'
user_id = "xxxxxx"
password = "xxxxx"
ip_user = "192.168.68.1"
lcurl="http://localhost/dukcapil/request6.php"
ohttp = CreateObject("Microsoft.XMLHTTP")
local lcparam
TEXT TO lcparam NOSHOW TEXTMERGE PRETEXT 7
nik=<<nik>>&user_id=<<user_id>>&password=<<password>>&ip_user=<<ip_user>>
ENDTEXT
ohttp.open("POST", lcurl, .F.)
ohttp.setrequestheader('Content-Type', 'application/json;')
ohttp.setrequestheader('Content-length', alltrim(str(len(lcparam))) )
ohttp.setrequestheader('Connection', 'close')
ohttp.send(lcparam)
ohttp.status
lcjson= ohttp.responseText
JSONStart()
oHasil = JSONObject(lcjson)


hasil respon Json dari request6.php
Code: [Select]
{"content":[{"NIK":3671110xxxxxxxxx,"NAMA_LGKP":"DANNY XXXXX","KAB_NAME":"KOTA XXX","NO_RW":5,"KEC_NAME":"XXX","JENIS_PKRJN":"KARYAWAN SWASTA","NO_RT":6,"NO_KEL":1001,"ALAMAT":"XXXXXXXXX","NO_KEC":11,"TMPT_LHR":"XXXX","STATUS_KAWIN":"KAWIN","NO_PROP":36,"NAMA_LGKP_IBU":"NAMA IBU","PROP_NAME":"JAKARTA","NO_KAB":71,"KEL_NAME":"XXX","JENIS_KLMIN":"Laki-Laki","TGL_LHR":"1980-01-09"}],"lastPage":true,"numberOfElements":1,"sort":null,"totalElements":1,"firstPage":true,"number":0,"size":1}1

tdk bisa masukkan gambar  :icon_biggrin:
https://imgur.com/OqNc7H1
mas emank pakai class nya nfJson ga?setau saya pakai nfJsonRead untuk membaca json, bukan JSONStart()
 kayanya mas pakai class dr qdfoxjson yaa

coba deh mas pakai class nfjson mas sesuai link yang saya kasih mas, itu ada contoh penggunaanya, atau mau liat dr blog saya ada https://rubahmania.wordpress.com/2017/05/01/foxpropenggunaan-nfjson/
« Last Edit: November 17, 2018, 09:18:43 PM by Atmanegara »
Cara terbaik untuk membuat mimpi Anda menjadi kenyataan adalah dengan bangun dari tidur

Offline dan2y

  • Senior Member
  • *
  • Posts: 576
Re: Parser nilai dari web service ektp (hasil JSON)
« Reply #9 on: November 19, 2018, 10:20:09 AM »
iya mas atma saya pakai qdfoxjson, ini saya mau coba pakai nfjsaon

Offline dan2y

  • Senior Member
  • *
  • Posts: 576
Re: Parser nilai dari web service ektp (hasil JSON)
« Reply #10 on: November 19, 2018, 10:49:20 AM »
mantap mas atmanegara :thumbsup:, sudah berhasil pakai nfjason

Code: [Select]
lcRespons=nfJsonRead(lcjson)




Terima kasih :icon_salut: