Skip to content

Commit 3f8eb03

Browse files
committedJan 27, 2025
Allow objets have the latest ,
1 parent c201ea3 commit 3f8eb03

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed
 

‎Json/Test/test.mqh

+14-1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,19 @@ int TestCJson(void)
206206
ASSERT_EQUALS(json["choices"].JsonType(),ARRAY);
207207
ASSERT_EQUALS(json["choices"][0].JsonType(),OBJECT);
208208

209+
text =
210+
""
211+
+"{\r\n"
212+
+" \"choices\": [\r\n"
213+
+" {\r\n"
214+
+" }\r\n"
215+
+" ],\r\n"
216+
+"}\r\n";
217+
ASSERT_EQUALS((json=text), true);
218+
ASSERT_EQUALS(json.Type(), JSON_TYPE_OBJECT);
219+
ASSERT_EQUALS(json["choices"].JsonType(),ARRAY);
220+
ASSERT_EQUALS(json["choices"][0].JsonType(),OBJECT);
221+
209222
text =
210223
""
211224
+"{\r\n"
@@ -249,7 +262,7 @@ int TestCJson(void)
249262
ASSERT_EQUALS(json["choices"][0].JsonType(),OBJECT);
250263
ASSERT_EQUALS(json["choices"][0]["message"].JsonType(),OBJECT);
251264
ASSERT_EQUALS(json["choices"][0]["message"]["content"].JsonType(),STRING);
252-
//ASSERT_EQUALS(json["choices"][0]["message"]["content"].Value(), "Ação: Comprar; Preço De Entrada: 1.4900; Stop: 1.4800; Take: 1.5100; Motivo: A recente recuperação do preço acima da média móvel, juntamente com o RSI em tendência de alta, sugere um impulso positivo.\",\r\n");
265+
ASSERT_EQUALS(json["choices"][0]["message"]["content"].Value(), "Ação: Comprar; Preço De Entrada: 1.4900; Stop: 1.4800; Take: 1.5100; Motivo: A recente recuperação do preço acima da média móvel, juntamente com o RSI em tendência de alta, sugere um impulso positivo.");
253266

254267
// array with 2 object
255268
ASSERT_EQUALS((json="[{},{}]"), true);

‎Json/classes/base.mqh

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ string CJsonBase::Trim(const string text)
116116
{
117117
const int total = StringLen(text);
118118
ushort c;
119-
int s = -1;
119+
int s = 0;
120120
for(int i=0; i < total; i++)
121121
{
122122
c = StringGetCharacter(text,i);
@@ -131,7 +131,7 @@ string CJsonBase::Trim(const string text)
131131
s = i;
132132
break;
133133
}
134-
int e = -1;
134+
int e = total-1;
135135
for(int i=total-1; i>=0; i--)
136136
{
137137
c = StringGetCharacter(text,i);
@@ -146,7 +146,7 @@ string CJsonBase::Trim(const string text)
146146
e = i;
147147
break;
148148
}
149-
return StringSubstr(text,s,e-s);
149+
return StringSubstr(text,s,e-s+1);
150150
}
151151
//+------------------------------------------------------------------+
152152
//| |

‎Json/classes/object.mqh

+13
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ bool CJsonObject::ProcessChildren(const string parse, const int start, const int
8686
return true;
8787
const string content = GetContent(parse,myStart+1,myEnd-1);
8888

89+
string tempValue;
90+
int tempLenght;
8991
string rightText;
9092
string key, value;
9193
int valueReaded;
@@ -105,6 +107,17 @@ bool CJsonObject::ProcessChildren(const string parse, const int start, const int
105107
i += reads;
106108
rightText = StringSubstr(content,i,total-1);
107109

110+
//remove last coma
111+
tempValue = Trim(rightText);
112+
if(tempValue == "")
113+
{
114+
tempValue = Trim(value);
115+
tempLenght = StringLen(tempValue);
116+
const ushort c = StringGetCharacter(tempValue,tempLenght-1);
117+
if(c == ',')
118+
value = StringSubstr(tempValue,0,tempLenght-1);
119+
}
120+
108121
if(!Add(key,value,valueReaded))
109122
return false;
110123

0 commit comments

Comments
 (0)
Please sign in to comment.