我有这样的JSON字符串在Delphi中,获取特定值
{
"bpd": {
"euro": {
"buying_rate": "48.50",
"selling_rate": "52.70"
},
"dollar": {
"buying_rate": "45.30",
"selling_rate": "45.80"
},
"source": "https://www.popularenlinea.com/_api/web/lists/getbytitle('Rates')/items"
},
"blh": {
"euro": {
"buying_rate": "48.50",
"selling_rate": "52.00"
},
"dollar": {
"buying_rate": "45.35",
"selling_rate": "45.80"
},
"source": "http://www.blh.com.do/Inicio.aspx"
}
}
我想提取美元buying_rate和selling_rate为银行BLH
我试试这个,但我得到AV
var
LJsonObj : TJSONObject;
LRows, LElements, LItem : TJSONValue;
begin
LJsonObj := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(s),0) as TJSONObject;
try
LRows:=LJsonObj.Get(0).JsonValue;
LElements:=TJSONObject(TJSONArray(LRows).Get(0)).Get(0).JsonValue;
LItem :=TJSONObject(TJSONArray(LElements).Get(0)).Get(0).JsonValue;
ShowMessage(TJSONObject(LItem).Get('buying_rate').JsonValue.Value);
finally
LJsonObj.Free;
end;