std.net.curl get json_encode
Vino
akashvino79 at gmail.com
Fri Oct 2 21:12:09 UTC 2020
Hi All,
Request your help, the below code is working but we need the
output as a json array, in PHP we have json_encode(content), so
how to do the same in D, the output is as below, as we need to
store this output into database table which contains columns'
(Id, Hostname, pool,email_id,username)
*******************
PHP
$jdata = json_encode(content);
foreach($jdata as $j) {
print_r($j["items"]["hostname"]);
*****************
OUTPUT:
{"items":
[
{"id":"1",
"hostname":"server1",
"pool":"dev",
"options":[
{"optionValue":"test1 at mail.com,test1"},
{"optionValue":"123"}
]
},
{"id":"2",
"hostname":"server2",
"pool":"dev",
"options":[
{"optionValue":"test2 at mail.com,test2"},
{"optionValue":"124"}
]
}
]
}
import std.net.curl, std.conv, std.stdio, std.json;
void main() {
auto https = HTTP();
https.handle.set(CurlOption.userpwd, "user:pass");
https.handle.set(CurlOption.connecttimeout, 600);
https.handle.set(CurlOption.tcp_nodelay, 1);
https.handle.set(CurlOption.buffersize, 1073741824);
https.handle.set(CurlOption.http_version, 2);
https.handle.set(CurlOption.sslversion, 1);
https.handle.set(CurlOption.use_ssl, 3);
https.handle.set(CurlOption.ssl_verifypeer, 0);
https.handle.set(CurlOption.url, "https://test.com/userlist");
https.method(HTTP.Method.get);
https.StatusLine status;
https.onReceiveStatusLine = (https.StatusLine s) { status = s; };
auto content = https.perform();
https.shutdown;
writeln(to!string(content));
}
From,
Vino.B
More information about the Digitalmars-d-learn
mailing list