www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Parseing single JSON value from webpage

reply "William Dunne" <william mimex.net> writes:
Sorry for the noob question.

I'm currently trying to parse this bit of json:

Array
(
     [meta] => Array
         (
             [level1trust] => 1
             [level2trust] => 9
         )

     [connections] => Array
         (
             [level1] => Array
                 (
                     [from] => name

                 )
///lots more json.

This seems like it could be done with std.json, however I'm 
struggling to understand how using my json object, I can get the 
value for level1trust

Anyone willing to lend a hand?
Apr 28 2015
parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Wednesday, 29 April 2015 at 02:34:20 UTC, William Dunne wrote:
 Sorry for the noob question.

 I'm currently trying to parse this bit of json:

 Array
 (
     [meta] => Array
         (
             [level1trust] => 1
             [level2trust] => 9
         )

     [connections] => Array
         (
             [level1] => Array
                 (
                     [from] => name

                 )
 ///lots more json.

 This seems like it could be done with std.json, however I'm 
 struggling to understand how using my json object, I can get 
 the value for level1trust

 Anyone willing to lend a hand?
auto json = `{"meta" : {"level1trust" : 1, "level2trust" : 9}}`; auto parsed = parseJSON(json); assert(parsed["meta"]["level1trust"].integer == 1); BTW, you probably know that, but your output is not JSON - it looks like a PHP dump.
Apr 28 2015