小编Sup*_*erc的帖子

如何在Delphi中解析JSON?

我有一个像这样的 JSON:

\n
{\n"Content": [{\n    "Identifier": "AABBCC",\n    "Description": "test terfdfg",\n    "GenericProductIdentifier": "AABBCC",\n    "ProductFamilyDescription": "sampling",\n    "LifeCycleStatus": "ACTIVE",\n    "Price": {\n        "Value": 1.00,\n        "Quantity": 1000\n    },\n    "LeadTimeWeeks": "16",\n    "FullBoxQty": 200,\n}],\n"TotalElements": 1,\n"TotalPages": 1,\n"NumberOfElements": 1,\n"First": true,\n"Size": 1,\n"Number": 0\n}\n
Run Code Online (Sandbox Code Playgroud)\n

在 Delphi 10.4 中,我尝试解析它,但无法访问 \'Price\' 中包含的值 \xe2\x80\x8b\xe2\x80\x8b。

\n

我写了这样的代码:

\n
var\n  vContent: TJSONArray;\n  vJson: TJSONObject;\n  vContentRow: TJSONObject;\n  i,j : Integer;\nbegin\n  Memo2.Lines.Clear;\n\n  if Memo1.Text = \'\' then\n    exit;\n\n  vJson := TJSONObject(TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(Memo1.Text),0));\n  try\n    vContent := TJSONArray(vJson.Get(\'Content\').JsonValue);\n\n    for i := 0 to Pred(vContent.Count) do\n    begin\n      vContentRow := TJSONObject(vContent.Items[i]);\n      for …
Run Code Online (Sandbox Code Playgroud)

delphi json

7
推荐指数
1
解决办法
5527
查看次数

标签 统计

delphi ×1

json ×1