All Bundles

JsonParser

Support for Json parsing

Operations

Code example:

doc := Web.HTTP.HttpsClient->QuickGet(Web.HTTP.Url->New("https://dummyjson.com/carts"));
if(doc <> Nil) {
   parser := Data.JSON.JsonParser->New(String->New(doc));
   if(parser->Parse()) {
      carts := parser->GetRoot()->Get("carts");
      if(carts->Size() > 0) {
         cart := carts->Get(Int->Random(carts->Size()));
         cart_id := cart->Get("id")->GetInt();
         "cart id={$cart_id}\n---"->PrintLine();
         products := cart->Get("products");
         each(product := products) {
            product_id := product->Get("id")->GetInt();
            product_title := product->Get("title")->GetString();
            "\tid={$product_id}, title: '{$product_title}'"->PrintLine();
         };
      };
   };
};

New

Creates a new parser

New(input:String)
Parameters
NameTypeDescription
inputStringJson input string

GetError

Get the current parsing error

method : public : GetError() ~ String
Return
TypeDescription
Stringparsing error, Nil if none

GetRoot

Get document root

method : public : GetRoot() ~ JsonElement
Return
TypeDescription
JsonElementroot Json element

Parse

Parses a Json string

method : public : Parse() ~ Bool
Return
TypeDescription
Booltrue is successful, false otherwise

TextToElement

Parses JSON text

function : TextToElement(text:String) ~ JsonElement
Parameters
NameTypeDescription
textStringJSON text

Return
TypeDescription
JsonElementroot document element