JsonParser
Support for JSON parsing
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();
};
};
};
};Operations
GetError
Get the current parsing error
method : public : GetError() ~ StringReturn
| Type | Description |
|---|---|
| String | parsing error, Nil if none |
GetRoot
Get document root
method : public : GetRoot() ~ JsonElementReturn
| Type | Description |
|---|---|
| JsonElement | root Json element |
New
Constructor
New(stream_in:String)Parameters
| Name | Type | Description |
|---|---|---|
| stream_in | String | JSON string to process |
Parse
Parses a Json string
method : public : Parse() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true is successful, false otherwise |
TextToElement
Parses JSON text
function : TextToElement(text:String) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| text | String | JSON text |
Return
| Type | Description |
|---|---|
| JsonElement | root document element |