Apock
28-03-2019, 02:38
С++ Builder 10.2
Пытаюсь освоить парсинг JSON, но что-то отсутствие толковой документации завелов тупик.
Есть такой ответ от сервера:
{
"timezone": "UTC",
"serverTime": 1508631584636,
"rateLimits": [
// These are defined in the `ENUM definitions` section under `Rate limiters (rateLimitType)`.
// All limits are optional.
],
"exchangeFilters": [
// There are defined in the `Filters` section.
// All filters are optional.
],
"symbols": [{
"symbol": "ETHBTC",
"status": "TRADING",
"baseAsset": "ETH",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8,
"orderTypes": [
// These are defined in the `ENUM definitions` section under `Order types (orderTypes)`.
// All orderTypes are optional.
],
"icebergAllowed": false,
"filters": [
// There are defined in the `Filters` section.
// All filters are optional.
]
}]
}
и вот такой код:
TJSONObject *o = (TJSONObject*) TJSONObject::ParseJSONValue(TEncoding::ASCII->GetBytes(Memo1->Lines->Text),0);
__try {
TJSONArray *a = (TJSONArray*) o->Get("symbols")->JsonValue;
for (int idx = 0; idx < a->Size(); idx++) {
TJSONObject *symbol = (TJSONObject*) a->Get(idx);
for (int idy = 0; idy < symbol->Count; idy++) {
ShowMessage( symbol->Pairs[idy]->JsonString->ToString() + ':' +
symbol->Pairs[idy]->JsonValue->ToString() );
}
}
}
__finally {
o->Free();
}
На третьей строке при попытке получить массив "symbols" вылетает ошибка Access Violation.
Если убрать всё остальное, к примеру так:
{
"symbols": [{
"symbol": "ETHBTC",
"status": "TRADING",
"baseAsset": "ETH",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8
}]
}
то всё проходит гладко и проблем не возникает.
Не могу понять как решить эту проблему.
Пытаюсь освоить парсинг JSON, но что-то отсутствие толковой документации завелов тупик.
Есть такой ответ от сервера:
{
"timezone": "UTC",
"serverTime": 1508631584636,
"rateLimits": [
// These are defined in the `ENUM definitions` section under `Rate limiters (rateLimitType)`.
// All limits are optional.
],
"exchangeFilters": [
// There are defined in the `Filters` section.
// All filters are optional.
],
"symbols": [{
"symbol": "ETHBTC",
"status": "TRADING",
"baseAsset": "ETH",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8,
"orderTypes": [
// These are defined in the `ENUM definitions` section under `Order types (orderTypes)`.
// All orderTypes are optional.
],
"icebergAllowed": false,
"filters": [
// There are defined in the `Filters` section.
// All filters are optional.
]
}]
}
и вот такой код:
TJSONObject *o = (TJSONObject*) TJSONObject::ParseJSONValue(TEncoding::ASCII->GetBytes(Memo1->Lines->Text),0);
__try {
TJSONArray *a = (TJSONArray*) o->Get("symbols")->JsonValue;
for (int idx = 0; idx < a->Size(); idx++) {
TJSONObject *symbol = (TJSONObject*) a->Get(idx);
for (int idy = 0; idy < symbol->Count; idy++) {
ShowMessage( symbol->Pairs[idy]->JsonString->ToString() + ':' +
symbol->Pairs[idy]->JsonValue->ToString() );
}
}
}
__finally {
o->Free();
}
На третьей строке при попытке получить массив "symbols" вылетает ошибка Access Violation.
Если убрать всё остальное, к примеру так:
{
"symbols": [{
"symbol": "ETHBTC",
"status": "TRADING",
"baseAsset": "ETH",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8
}]
}
то всё проходит гладко и проблем не возникает.
Не могу понять как решить эту проблему.