如何解析 Delphi 中的 JSON 字符串?

how can I parse a JSON string in Delphi?

如何使用 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":""
    }
  ]
}

使用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;