Catatan Programmer Perbatasan
IdHTTP,uLkJSON;
[Code Delphi
{]
"id_user": "19",
"NAMA": "Risman Arisandi",
"NIP": "198907252020101001"
},
{
"id_user": "18",
"NAMA": "Vivi",
"NIP": "198907252020101002"
},
{
"id_user": "17",
"NAMA": "Aidan",
"NIP": "198907252020101003"
},
{
"id_user": "16",
"NAMA": "Ulan",
"NIP": "198907252020101004"
}
{Code Delphi
"sukses": "1",
"data":[{"id_user": "19","NAMA": "Risman Arisandi","NIP": "198907252020101001"},{"id_user": "18","NAMA": "Vivi","NIP": "198907252020101002"},{"id_user": "17","NAMA": "Aidan","NIP": "198907252020101003"},{"id_user": "16","NAMA": "Ulan","NIP": "198907252020101004"}] }
[ { "userId": 1, "id": 1, "title": "quidem molestiae enim" }, { "userId": 1, "id": 2, "title": "sunt qui excepturi placeat culpa" }, { "userId": 1, "id": 3, "title": "omnis laborum odio" }, { "userId": 1, "id": 4, "title": "non esse culpa molestiae omnis sed optio" }]
Code Delphi2. Mengambil Json Object Method Get
{ "userId": 1, "id": 1, "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"}Code Delphi
{ "userId": 1, "id": 1Code Delphi
}
[ { "userId": 1, "id": 1, "title": "quidem molestiae enim" }, { "userId": 1, "id": 2, "title": "sunt qui excepturi placeat culpa" }, { "userId": 1, "id": 3, "title": "omnis laborum odio" }, { "userId": 1, "id": 4, "title": "non esse culpa molestiae omnis sed optio" }]Code delphi
{"status":"informasi",Code delphi
"message":"berhasil",
"data":[ { "userId": 1, "id": 1, "title": "quidem molestiae enim" }, { "userId": 1, "id": 2, "title": "sunt qui excepturi placeat culpa" }, { "userId": 1, "id": 3, "title": "omnis laborum odio" }, { "userId": 1, "id": 4, "title": "non esse culpa molestiae omnis sed optio" }]}
{ "id_user": "6", "NAMA": "Risandy Ka", "STATUS": "Aku Berada di rumah", "LATITUDE": "", "LONGITUDE": "", "TANGGAL": "2019-08-01 22:56:10" }Code Delphi :
procedure TFMain.Button1Click(Sender: TObject);varjsn : TJSONObject;begin
2. Mengambil JSONarrayDM.RESTClient_status.BaseURL := 'http://localhost/aplikasi/peg_status.php?act=onestatus&id_status=222';DM.RestRequest_status.ExecuteAsync();Sleep(2000);jsn := DM.RESTResponse_status.JSONValue as TJSONObject;Memo1.Text := jsn.Values['STATUS'].Value;TabControl_home.TabIndex := 3;end;
[{ "id_user": "6", "NAMA": "Risandy Ka", "STATUS": "Aku Berada di rumah", "LATITUDE": "", "LONGITUDE": "", "TANGGAL": "2019-08-01 22:56:10" },{ "id_user": "6", "NAMA": "Risandy Ka", "STATUS": "Dalam perjalanan", "LATITUDE": "", "LONGITUDE": "", "TANGGAL": "2019-08-01 22:56:10" },{ "id_user": "6", "NAMA": "Risandy Ka", "STATUS": "Lagi di kampus", "LATITUDE": "", "LONGITUDE": "", "TANGGAL": "2019-08-01 22:56:10" }]Code Delphi :
procedure TFMain.Button1Click(Sender: TObject);diatas adalah cara menggunakan komponen rest. berikut jika ingin menggunakan TNetHTTPClient dan IHTTPRespon menampilkan output json
var
id_user, NAMA, STATUS, LATITUDE, LONGITUDE, TANGGAL, URL : string;
JSN: TJSONObject;
JSNarry : TJSONArray;
begin
JSNarry := DM.RESTResponse_status.JSONValue as TJSONArray;
for i := 0 to JSNarry.Count do
begin
JSN := JSNarry.Items[i] as TJSONObject;
id_user := JSN.Values['id_user'].Value;
NAMA := JSN.Values['NAMA'].Value;
STATUS := JSN.Values['STATUS'].Value;
LATITUDE := JSN.Values['LATITUDE'].Value;
LONGITUDE := JSN.Values['LONGITUDE'].Value;
TANGGAL := JSN.Values['TANGGAL'].Value;
Add_status(id_user, NAMA, STATUS, LATITUDE, LONGITUDE, TANGGAL, LV);
end;
end;
[jika digunakan di browser tidak akan tampil harus jadi menggunakan restdebugger untuk mengetahui outputnya
{
"id_user":"13",
"id_fb":null,
"NAMA":"VIVI PRATIWI",
"EMAIL":"viri@gmail.com"
}
]
elseif ($act=='login1'){ $EMAIL = $_POST['EMAIL']; $NAMA = $_POST['NAMA']; $data = mysql_query("SELECT id_user, id_fb, NAMA, EMAIL FROM peg_user WHERE EMAIL='$EMAIL' and NAMA='$NAMA'"); if (mysql_num_rows($data)>0){ while ($row = mysql_fetch_assoc($data)){ $respon[] = $row; } } else { } echo json_encode($respon,JSON_PRETTY_PRINT); }nah untuk mengambil value json nya di delphi :
procedure TFMain.Button1Click(Sender: TObject);ingat contoh tadi jika json nya array. jika bukan array tinggal disesuaikan saja.
var
idh : TNetHTTPClient;
params: TStringList;
s, strjsn : string;
httpresult : IHTTPResponse ;
jo: TJSONObject;
jv, jvl:TJSONValue;
begin
idh := TNetHTTPClient.Create(self);
try
params:=tstringlist.Create;
params.AddPair('EMAIL',edt_EMAIL.Text);
params.AddPair('NAMA',edt_NAMA.Text);
httpresult := idh.Post('http://rasoftware.net/aplikasi/service_nugo/peg_user.php?act=login1', params);
finally
idh.Free;
end;
strjsn:=httpresult.ContentAsString();
jvl := tjsonobject.ParseJSONValue(strjsn);
If jvl is tjsonarray then
for jv in (jvl as TJSONArray) do
begin
if jv is tjsonobject then
begin
jo := jv as tjsonobject;
s := jo.GetValue<string>('id_user');
edt_id_user.Text:= s;
end;
end;
end;
procedure TForm1.FormResize(Sender: TObject);
var
ctrl : TControl;
begin
if FlowLayout1.controlsCount > 0 then
begin
ctrl := FlowLayout1.controls [FlowLayout1.controlsCount - 1];
FlowLayout1.height := ctrl.position.y + ctrl.height ; //+ ... // allow for margins and padding if needed.
end;
end;
RESTClient1.BaseURL := 'http://localhost/esurat/surat_masuk.php?act=tampil'; RestRequest1.ExecuteAsync();
procedure TForm1.Button2Click(Sender: TObject);
Var
i : integer;
item : TListViewItem;
txt : TListItemText;
img : TListItemImage;
begin
for i := 1 to FDMemTable1.RecordCount do
begin
item := ListView1.Items.Add;
with item do
begin
txt := TListItemText(Objects.FindDrawable('Text1'));
txt.Text := FDMemTable1.FieldByName('PENGIRIM').AsString;;
txt.Font.Size := 11;
txt.Font.Style := [TFontStyle.fsBold];
txt := TListItemText(Objects.FindDrawable('Text2'));
txt.Text := FDMemTable1.FieldByName('TANGGAL_SURAT').AsString;;
txt.Font.Size := 11;
txt.Font.Style := [TFontStyle.fsBold];
end;
FDMemtable1.Next;
end;
end;
<?php
// CONECT DATABASE
include('koneksi.php');
$id = $_GET['id'];
$sqll="SELECT * FROM `file_attachment` WHERE `id`='$id'";
$query=mysql_query($sqll) or die(mysql_error());
$result=mysql_fetch_array($query);
$content=$result['file_content'];
?>
<object data="data:application/pdf;base64,<?php echo base64_encode($content); ?>" type="application/pdf" style="height:98%;width:100%"></object>