如何使用TJSONObject对象解析此JSON字符串?
{
"status":"OK",
"num_results":"2",
"results":[
{
"title":"",
"quantity":"",
"cook_time":"",
"level":"",
"master_ingr":"",
"sub_ingr":"",
"cook1":"",
"cook2":"",
"cook3":"",
"cook4":"",
"cook5":"",
"cook6":"",
"cook_tip1":"",
"cook_tip2":"",
"cook_tip3":"",
"cook_tip4":"",
"cook_tip5":"",
"cook_tip6":""
},
{
"title":" ",
"quantity":"",
"cook_time":"",
"level":"",
"master_ingr":"",
"sub_ingr":"",
"cook1":"",
"cook2":"",
"cook3":"",
"cook4":"",
"cook5":"",
"cook6":"",
"cook_tip1":"",
"cook_tip2":"",
"cook_tip3":"",
"cook_tip4":"",
"cook_tip5":"",
"cook_tip6":""
}
]
}
答案 0 :(得分:1)
使用TJSONObject.ParseJSONValue()
方法:
class function ParseJSONValue(const Data: string; UseBool: Boolean = False): TJSONValue; overload; static;
例如:
var
S: string;
JObj: TJSONObject;
begin
S := ...;
JObj := TJSONObject.ParseJSONValue(S) as TJSONObject;
try
...
finally
JObj.Free;
end;