std.net.curl get json_encode
Vino
akashvino79 at gmail.com
Sun Oct 11 08:48:16 UTC 2020
On Friday, 9 October 2020 at 17:50:16 UTC, Andre Pany wrote:
> On Friday, 9 October 2020 at 05:56:05 UTC, Vino wrote:
>> On Friday, 9 October 2020 at 05:30:34 UTC, ikod wrote:
>>> On Friday, 9 October 2020 at 01:45:37 UTC, Vino wrote:
>>>> 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,
>>> ...
>>>> auto content = https.perform();
>>>> https.shutdown;
>>>> JSONValue jv = parseJSONValue(content);
>>>
>>> Maybe
>>> JSONValue jv = toJSONValue(content);
>>>
>>>
>>>> writeln(jv["Name"]);
>>>>
>>>> }
>>>>
>>>> From,
>>>> Vino
>>
>> Hi Ikod,
>>
>> No luck.
>>
>> Error
>> test.d(19): Error: template
>> `stdx.data.json.parser.toJSONValue` cannot deduce function
>> from argument types `!()(int)`, candidates are:
>> C:\D\dmd2\windows\bin\..\..\src\phobos\stdx\data\json\parser.d(58): `toJSONValue(LexOptions options = LexOptions.init, Input)(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(65): `toJSONValue(Input)(Input tokens, int maxDepth = defaultMaxDepth)`
>> with `Input = int`
>> whose parameters have the following constraints:
>> `~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
>> ` > isJSONTokenInputRange!Input
>> ` `~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
>> datacoll.d(19): All possible candidates are marked as
>> `deprecated` or `@disable`
>> Tip: not satisfied constraints are marked with `>`
>>
>> From,
>> Vino
>
> (Writing from my mobile, a lot of room for improvements):
>
> import std.net.curl, std.stdio;
>
> // GET with custom data receivers
> auto http = HTTP("dlang.org");
> http.onReceiveHeader =
> (in char[] key, in char[] value) { writeln(key, ": ",
> value); };
>
> ubyte[] content;
> http.onReceive = (ubyte[] data) {
> content ~= data;
> return data.length; };
> http.perform();
>
> string s = cast(string) content;
>
> Kind regards
> Andre
Hi Andre,
Thank you very much, now we are able to get the data as
expected using jv["Name"], now when we try to print all the
returned data with Key and Values as below it is thorwing an error
Error:
Error: template `object.byKeyValue` cannot deduce function from
argument types `!()(JSONValue)`
Code:
string s = cast(string) content;
JSONValue jv = parseJSONValue(s);
writeln(jv["Name"]; \\ this works.
foreach (key, value; jv.byKeyValue) writefln("%s: %s", key,
value); \\ this does not work.
From,
Vino
More information about the Digitalmars-d-learn
mailing list