std.net.curl get json_encode

Vino akashvino79 at gmail.com
Fri Oct 9 01:45:37 UTC 2020


On Friday, 2 October 2020 at 23:20:48 UTC, Imperatorn wrote:
> On Friday, 2 October 2020 at 21:12:09 UTC, Vino wrote:
>> 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)
>>
>> [...]
>
> I also suggest you take a look at other "json packages" as well:
> https://code.dlang.org/search?q=json
>
> For example std_data_json or asdf

Hi,

  I tired sdt_data_json, still no luck, the output of the url is 
as below

Output : {"Name":"testuser","Site":"1-east"}

Error :
test.d(20): Error: template 
`stdx.data.json.parser.parseJSONValue` cannot deduce function 
from argument types `!()(int)`, candidates are:
C:\D\dmd2\windows\bin\..\..\src\phobos\stdx\data\json\parser.d(133):        `parseJSONValue(LexOptions options = LexOptions.init, Input)(ref Input input, string filename = "", int maxDepth = defaultMaxDepth)`
   with `options = cast(LexOptions)0,
        Input = int`
   whose parameters have the following constraints:
   `~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
`  > isInputRange!Input
       - isSomeChar!(ElementType!Input)
         or:
       - isIntegral!(ElementType!Input)
`  `~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
C:\D\dmd2\windows\bin\..\..\src\phobos\stdx\data\json\parser.d(178):        `parseJSONValue(Input)(ref Input tokens, int maxDepth = defaultMaxDepth)`
   with `Input = int`
   whose parameters have the following constraints:
   `~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
`  > isJSONTokenInputRange!Input
`  `~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
datacoll.d(20):        All possible candidates are marked as 
`deprecated` or `@disable`
   Tip: not satisfied constraints are marked with `>`

Code:
import std.net.curl, std.conv, std.stdio, stdx.data.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/getUser");
https.method(HTTP.Method.get);
https.StatusLine status;
auto content = https.perform();
https.shutdown;
JSONValue jv = parseJSONValue(content);
writeln(jv["Name"]);

}

From,
Vino


More information about the Digitalmars-d-learn mailing list