string pJS=" ... "// Json Sample
js.Deserialize(pJS);
Print(js["nome"].ToStr()); // is correct = 12.01 alteradoPrint(js["condicoes"].m_type); // is correct type 6 or jtARRAYPrint(js["condicoes"].Size()); //not work ... return 1, but correct 2
When a value is null, Deserialize() sets the type to jtNULL, but doesn't assign NULL to m_sv, so if ToStr() method is compared to NULL it returns false:
#include <JAson.mqh>
//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+voidOnStart()
{
string serialized="{\"a\":1,\"b\":null}";
CJAVal json;
json.Deserialize(serialized);
if(json["b"].ToStr()==NULL)
{
Alert("b is NULL");
}
elseif(json["b"].ToStr()=="")
{
Alert("b is an empty string");
}
else
{
Alert("b is ", json["b"].ToStr());
}
}
The output is:
2022.03.28 17:50:02.833test-jsonNULLComparison (GBPUSD,M30)Alert: b is an empty string
The workaround would be comparing the type of value to jtNULL or change the source code at line 220 by adding "m_sv=NULL;":
if (i+3<slen) if (StringCompare(GetStr(js, i, 4), "null", false)==0) { m_sv=NULL; i+=3; returntrue; }
Artem Maltsev, I recommend you to add my version, because those who downloaded the module will not be able to do so: #107.
Can you tell me how to add rounding to double?
There is an option below, but it adds square brackets.
How to get?
{ "id": 54, "nome": "12.01 alterado", "condicoes": [ { "id": 47, "estrategiaId": 54, "indicadorAId": 87, "indicadorA": { "id": 87, "nome": "iATR", "parametros": [ { "id": 46, "nome": null, "valor": 10.0 } ] }, "retornoA": 0, "comparador": ">", "indicadorBId": 88, "indicadorB": { "id": 88, "nome": "iAMA", "parametros": [ { "id": 47, "nome": "Aplicar a", "valor": 1.0 }, { "id": 48, "nome": "Periodo rapido", "valor": 2.0 }, { "id": 49, "nome": "Periodo lento", "valor": 3.0 }, { "id": 50, "nome": "Deslocalmento", "valor": 4.0 }, { "id": 51, "nome": "Aplicar a", "valor": 0.0 } ] }, "retornoB": 0 }, { "id": 48, "estrategiaId": 54, "indicadorAId": 90, "indicadorA": { "id": 90, "nome": "iATR", "parametros": [ { "id": 52, "nome": null, "valor": 10.0 } ] }, "retornoA": 0, "comparador": ">", "indicadorBId": 89, "indicadorB": { "id": 89, "nome": "iAMA", "parametros": [ { "id": 53, "nome": "Aplicar a", "valor": 1.0 }, { "id": 54, "nome": "Periodo rapido", "valor": 2.0 }, { "id": 55, "nome": "Periodo lento", "valor": 3.0 }, { "id": 56, "nome": "Deslocalmento", "valor": 4.0 }, { "id": 57, "nome": "Aplicar a", "valor": 0.0 } ] }, "retornoB": 0 } ] }It works properly on my computer. How do you put the json string into the pJS variable?
@Artem Maltsev Thank you for creating this JSON library. Is it based on some C++ library?
Do you have some performance benchmarks on this? Also, does it internally use 1 byte or 2 byte chars to store the data?
When a value is null, Deserialize() sets the type to jtNULL, but doesn't assign NULL to m_sv, so if ToStr() method is compared to NULL it returns false:
The output is:
2022.03.28 17:50:02.833 test-jsonNULLComparison (GBPUSD,M30) Alert: b is an empty string
The workaround would be comparing the type of value to jtNULL or change the source code at line 220 by adding "m_sv=NULL;":
Good afternoon!
Cool library helps a lot, thank you very much.
I just encountered this problem - how to extract a substring from a string:
There is a string
{"type": "settings", "data":{"auto_trade":true, "stop_trade":true}}}
I need to pull out the data substring.
It doesn't work that way:
CJAVal js;
js.Deserialise(stroka);
js["data"].ToStr();
Good afternoon!
Cool library is very helpful, thank you very much.
I just encountered this problem - how to extract a substring from a string:
There is a string
{"type": "settings", "data":{"auto_trade":true, "stop_trade":true}}
I need to pull out the data substring.
It doesn't work that way:
CJAVal js;
js.Deserialize(stroka);
js["data"].ToStr();
I have found only one way to pull out the required substring so far:
js.Deserialize(stroka);
string data2=js["data"].Serialize();
js2.Deserialise(data2);
I.e. the required substring should be serialized and deserialised separately.
Can you tell me how to add rounding to double?
There is a variant below, but it adds square brackets.
How to get?
Try it like this:
Unfortunately, something didn't work again.
How are you supposed to learn from codes that don't work?
I have now tried it with GET and POST.
"meine adresse"is of course the URL to a page on which the response is displayed as
{"isValid":true}
Or
{"isValid":false}
as the response.
However, if I use
absolutely nothing.
What is the reason for this?