Support for JSON parsing
OperationsCode 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();
};
};
};
};
Constructor
New(stream_in:String)
Name | Type | Description |
---|---|---|
stream_in | String | JSON string to process |
Constructor
New(stream_in:Char[])
Name | Type | Description |
---|---|---|
stream_in | Char[] | JSON character stream |
Constructor
New(stream_in:Byte[])
Name | Type | Description |
---|---|---|
stream_in | Byte[] | JSON byte stream |
Get the current parsing error
method : public : GetError() ~ String
Type | Description |
---|---|
String | parsing error, Nil if none |
Get document root
method : public : GetRoot() ~ JsonElement
Type | Description |
---|---|
JsonElement | root Json element |
Parses a Json string
method : public : Parse() ~ Bool
Type | Description |
---|---|
Bool | true is successful, false otherwise |
Parses JSON text
function : TextToElement(text:String) ~ JsonElement
Name | Type | Description |
---|---|---|
text | String | JSON text |
Type | Description |
---|---|
JsonElement | root document element |