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":"te...@mail.com,test1"},
                        {"optionValue":"123"}
                        ]
                },
                {"id":"2",
                "hostname":"server2",
                "pool":"dev",
                "options":[
                        {"optionValue":"te...@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

Reply via email to