0
如何解析這裏該行於2010年德爾福:德爾福2010 JSON解析
{"list": [{"id": "107","name": "John","fname": "Doe"},
{"id": "108","name": "Alex","fname": "Man"}],
"success": 1,
"count": "2"}
如何解析這裏該行於2010年德爾福:德爾福2010 JSON解析
{"list": [{"id": "107","name": "John","fname": "Doe"},
{"id": "108","name": "Alex","fname": "Man"}],
"success": 1,
"count": "2"}
procedure parse_3;
var
txt: PAnsiChar;
js: TJSONArray;
lat: string;
i: integer;
begin
try
txt :=
'{"list": [{"id": "107","name": "John","fname": "Doe"},{"id": "108","name": "Alex","fname": "Man"}],"success": 1, "count": "2"}';
js := ParseJSON(txt);
except
end;
if Assigned(js) and (js is TJSONObject) then
begin
if js.field['success'].value = 1 then
begin
for i := 0 to StrToInt(js.field['count'].value) - 1 do
begin
showmessage(js.field['list'].child[i].field['id'].value +' | '+js.field['list'].child[i].field['name'].value +' | '+js.field['list'].child[i].field['fname'].value);
end;
end;
end;
end;
如果引發一個異常,那麼你吞下它並且'js'沒有被初始化,因此後面所有使用'js'都是無效的。 –
爲了解析JSON,使用JSON解析器。 –
我試圖重做各種解析示例,但失敗=( – Antuan
您正在使用哪個JSON解析器?您知道JSON解析器是什麼嗎?如果您的答案是否定的,那麼很好,然後我們可以告訴您並讓您的生活更輕鬆。 –