Delphi JsonTextReader fails to read values
In the JSON you have shown, all of the values are strings, there are no integers. So, when you call jtr.Value.AsInteger
for the message_count
value, it raises a conversion exception that you are not catching. TValue.AsInteger
DOES NOT perform an implicit conversion from string to integer for you.
You will have to use jtr.Value.AsString
instead and convert the string to an integer using StrToInt()
:
if jtr.Value.ToString = 'message_count' thenbegin jtr.Read; //c.msg := jtr.Value.AsInteger; c.msg := StrToInt(jtr.Value.AsString);end;
Do the same for the other "integer" values in the JSON (alerts_unread
, like_count
, and friend_count
).