我似乎有点解决JSON,但不是所有的JSON有问题。我从Shopify提取数据,当我获取products.json时,它解析正确。当我得到一个特定的产品时,我得到一个'Invalid Class Typecast'错误。德尔福XE4解析JSON
在Delphi XE4中使用dbxjson.pas,我只是在学习如何使用它。以下代码中的一部分来自对前面关于一般使用JSON解析器的问题的回答。
我只是将JSON放入备注字段,然后调用parsejson2(memo1.text),并将结果放入备忘录2中。
我正确地获取JSON,并通过json.parser.online.fr验证了它是正确的。
这里是JSON输出与代码的工作,我有:
{"products":[{"id":11332270357,"title":"Burton Custom Freestyle 151","body_html":"\u003cstrong\u003eGood snowboard!\u003c\/strong\u003e","vendor":"Burton","product_type":"Snowboard","created_at":"2017-07-26T12:55:21-04:00","handle":"burton-custom-freestyle-151","updated_at":"2017-07-26T12:55:21-04:00","published_at":"2017-07-26T12:55:21-04:00","template_suffix":null,"published_scope":"global","tags":"\"Big Air\", Barnes \u0026 Noble, John's Fav","variants":[{"id":48188219989,"product_id":11332270357,"title":"Default Title","price":"0.00","sku":"","position":1,"grams":0,"inventory_policy":"deny","compare_at_price":null,"fulfillment_service":"manual","inventory_management":null,"option1":"Default Title","option2":null,"option3":null,"created_at":"2017-07-26T12:55:21-04:00","updated_at":"2017-07-26T12:55:21-04:00","taxable":true,"barcode":null,"image_id":null,"inventory_quantity":1,"weight":0.0,"weight_unit":"lb","old_inventory_quantity":1,"requires_shipping":true}],"options":[{"id":13730250389,"product_id":11332270357,"name":"Title","position":1,"values":["Default Title"]}],"images":[],"image":null},{"id":11400089237,"title":"Pile of Rocks","body_html":"Wicked cool pile of rocks from Hawaii!","vendor":"test_titan","product_type":"","created_at":"2017-08-01T09:44:11-04:00","handle":"pile-of-rocks","updated_at":"2017-08-01T09:44:54-04:00","published_at":"2017-08-01T09:40:55-04:00","template_suffix":null,"published_scope":"global","tags":"","variants":[{"id":48653472149,"product_id":11400089237,"title":"pile \/ various","price":"1000.00","sku":"12345678974346547000","position":1,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"pile","option2":"various","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472213,"product_id":11400089237,"title":"pile \/ green","price":"1000.00","sku":"12345678974346547000","position":2,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"pile","option2":"green","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472277,"product_id":11400089237,"title":"pile \/ blue","price":"1000.00","sku":"12345678974346547000","position":3,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"pile","option2":"blue","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472341,"product_id":11400089237,"title":"pile \/ purple","price":"1000.00","sku":"12345678974346547000","position":4,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"pile","option2":"purple","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472405,"product_id":11400089237,"title":"pile \/ red","price":"1000.00","sku":"12345678974346547000","position":5,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"pile","option2":"red","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472469,"product_id":11400089237,"title":"hill \/ various","price":"1000.00","sku":"12345678974346547000","position":6,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"hill","option2":"various","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472533,"product_id":11400089237,"title":"hill \/ green","price":"1000.00","sku":"12345678974346547000","position":7,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"hill","option2":"green","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472597,"product_id":11400089237,"title":"hill \/ blue","price":"1000.00","sku":"12345678974346547000","position":8,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"hill","option2":"blue","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472661,"product_id":11400089237,"title":"hill \/ purple","price":"1000.00","sku":"12345678974346547000","position":9,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"hill","option2":"purple","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472725,"product_id":11400089237,"title":"hill \/ red","price":"1000.00","sku":"12345678974346547000","position":10,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"hill","option2":"red","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472789,"product_id":11400089237,"title":"mountain \/ various","price":"1000.00","sku":"12345678974346547000","position":11,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"mountain","option2":"various","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472853,"product_id":11400089237,"title":"mountain \/ green","price":"1000.00","sku":"12345678974346547000","position":12,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"mountain","option2":"green","option3":null,"created_at":"2017-08-01T09:44:12-04:00","updated_at":"2017-08-01T09:44:12-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472917,"product_id":11400089237,"title":"mountain \/ blue","price":"1000.00","sku":"12345678974346547000","position":13,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"mountain","option2":"blue","option3":null,"created_at":"2017-08-01T09:44:12-04:00","updated_at":"2017-08-01T09:44:12-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472981,"product_id":11400089237,"title":"mountain \/ purple","price":"1000.00","sku":"12345678974346547000","position":14,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"mountain","option2":"purple","option3":null,"created_at":"2017-08-01T09:44:12-04:00","updated_at":"2017-08-01T09:44:12-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653473045,"product_id":11400089237,"title":"mountain \/ red","price":"1000.00","sku":"12345678974346547000","position":15,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"mountain","option2":"red","option3":null,"created_at":"2017-08-01T09:44:12-04:00","updated_at":"2017-08-01T09:44:12-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true}],"options":[{"id":13812358421,"product_id":11400089237,"name":"Size","position":1,"values":["pile","hill","mountain"]},{"id":13812358485,"product_id":11400089237,"name":"Color","position":2,"values":["various","green","blue","purple","red"]}],"images":[{"id":28069860373,"product_id":11400089237,"position":1,"created_at":"2017-08-01T09:44:54-04:00","updated_at":"2017-08-01T09:44:54-04:00","width":4096,"height":2304,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/2130\/9415\/products\/20161010_173112.jpg?v=1501595094","variant_ids":[]}],"image":{"id":28069860373,"product_id":11400089237,"position":1,"created_at":"2017-08-01T09:44:54-04:00","updated_at":"2017-08-01T09:44:54-04:00","width":4096,"height":2304,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/2130\/9415\/products\/20161010_173112.jpg?v=1501595094","variant_ids":[]}},{"id":11319164053,"title":"Test Product","body_html":"This is a test product only for testing API.","vendor":"test_titan","product_type":"","created_at":"2017-07-24T16:05:00-04:00","handle":"test-product","updated_at":"2017-07-25T14:20:01-04:00","published_at":"2017-07-24T16:04:07-04:00","template_suffix":null,"published_scope":"global","tags":"","variants":[{"id":48023373269,"product_id":11319164053,"title":"Default Title","price":"10000.00","sku":"11226644","position":1,"grams":0,"inventory_policy":"deny","compare_at_price":"50.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"Default Title","option2":null,"option3":null,"created_at":"2017-07-24T16:05:00-04:00","updated_at":"2017-07-24T16:05:00-04:00","taxable":true,"barcode":"123456789","image_id":null,"inventory_quantity":20,"weight":0.0,"weight_unit":"lb","old_inventory_quantity":20,"requires_shipping":true}],"options":[{"id":13711000789,"product_id":11319164053,"name":"Title","position":1,"values":["Default Title"]}],"images":[],"image":null}]}
这里是JSON输出不工作:
{"product":{"id":11400089237,"title":"Pile of Rocks","body_html":"Wicked cool pile of rocks from Hawaii!","vendor":"test_titan","product_type":"","created_at":"2017-08-01T09:44:11-04:00","handle":"pile-of-rocks","updated_at":"2017-08-01T09:44:54-04:00","published_at":"2017-08-01T09:40:55-04:00","template_suffix":null,"published_scope":"global","tags":"","variants":[{"id":48653472149,"product_id":11400089237,"title":"pile \/ various","price":"1000.00","sku":"12345678974346547000","position":1,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"pile","option2":"various","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472213,"product_id":11400089237,"title":"pile \/ green","price":"1000.00","sku":"12345678974346547000","position":2,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"pile","option2":"green","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472277,"product_id":11400089237,"title":"pile \/ blue","price":"1000.00","sku":"12345678974346547000","position":3,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"pile","option2":"blue","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472341,"product_id":11400089237,"title":"pile \/ purple","price":"1000.00","sku":"12345678974346547000","position":4,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"pile","option2":"purple","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472405,"product_id":11400089237,"title":"pile \/ red","price":"1000.00","sku":"12345678974346547000","position":5,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"pile","option2":"red","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472469,"product_id":11400089237,"title":"hill \/ various","price":"1000.00","sku":"12345678974346547000","position":6,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"hill","option2":"various","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472533,"product_id":11400089237,"title":"hill \/ green","price":"1000.00","sku":"12345678974346547000","position":7,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"hill","option2":"green","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472597,"product_id":11400089237,"title":"hill \/ blue","price":"1000.00","sku":"12345678974346547000","position":8,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"hill","option2":"blue","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472661,"product_id":11400089237,"title":"hill \/ purple","price":"1000.00","sku":"12345678974346547000","position":9,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"hill","option2":"purple","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472725,"product_id":11400089237,"title":"hill \/ red","price":"1000.00","sku":"12345678974346547000","position":10,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"hill","option2":"red","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472789,"product_id":11400089237,"title":"mountain \/ various","price":"1000.00","sku":"12345678974346547000","position":11,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"mountain","option2":"various","option3":null,"created_at":"2017-08-01T09:44:11-04:00","updated_at":"2017-08-01T09:44:11-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472853,"product_id":11400089237,"title":"mountain \/ green","price":"1000.00","sku":"12345678974346547000","position":12,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"mountain","option2":"green","option3":null,"created_at":"2017-08-01T09:44:12-04:00","updated_at":"2017-08-01T09:44:12-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472917,"product_id":11400089237,"title":"mountain \/ blue","price":"1000.00","sku":"12345678974346547000","position":13,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"mountain","option2":"blue","option3":null,"created_at":"2017-08-01T09:44:12-04:00","updated_at":"2017-08-01T09:44:12-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653472981,"product_id":11400089237,"title":"mountain \/ purple","price":"1000.00","sku":"12345678974346547000","position":14,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"mountain","option2":"purple","option3":null,"created_at":"2017-08-01T09:44:12-04:00","updated_at":"2017-08-01T09:44:12-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true},{"id":48653473045,"product_id":11400089237,"title":"mountain \/ red","price":"1000.00","sku":"12345678974346547000","position":15,"grams":14,"inventory_policy":"deny","compare_at_price":"9999.00","fulfillment_service":"manual","inventory_management":"shopify","option1":"mountain","option2":"red","option3":null,"created_at":"2017-08-01T09:44:12-04:00","updated_at":"2017-08-01T09:44:12-04:00","taxable":true,"barcode":"44569874345654","image_id":null,"inventory_quantity":1,"weight":0.5,"weight_unit":"oz","old_inventory_quantity":1,"requires_shipping":true}],"options":[{"id":13812358421,"product_id":11400089237,"name":"Size","position":1,"values":["pile","hill","mountain"]},{"id":13812358485,"product_id":11400089237,"name":"Color","position":2,"values":["various","green","blue","purple","red"]}],"images":[{"id":28069860373,"product_id":11400089237,"position":1,"created_at":"2017-08-01T09:44:54-04:00","updated_at":"2017-08-01T09:44:54-04:00","width":4096,"height":2304,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/2130\/9415\/products\/20161010_173112.jpg?v=1501595094","variant_ids":[]}],"image":{"id":28069860373,"product_id":11400089237,"position":1,"created_at":"2017-08-01T09:44:54-04:00","updated_at":"2017-08-01T09:44:54-04:00","width":4096,"height":2304,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/2130\/9415\/products\/20161010_173112.jpg?v=1501595094","variant_ids":[]}}}
我可以看到两者之间的主要区别是方括号[],但我仍然不知道为什么它不解析第二个。任何帮助是极大的赞赏。
procedure TForm1.parsejson2(s, sKey: string);
var
jsv : TJsonValue;
originalObject : TJsonObject;
jsPair : TJsonPair;
jsArr : TJsonArray;
jso : TJsonObject;
i,j : integer;
aos : Tarray<string>;
sValue : String;
begin
try
//parse json string
jsv := TJSONObject.ParseJSONValue(s);
try
//value as object
originalObject := jsv as TJsonObject;
//get pair, wich contains Array of objects
jspair := originalObject.Get(sKey);
//pair value as array
jsArr := jsPair.jsonValue as TJsonArray;
//enumerate objects in array
for i := 0 to jsArr.Size - 1 do
begin // i-th object
try
jso := jsArr.Get(i) as TJsonObject;
except
end;
//enumerate object fields
for jsPair in jso do
begin
Memo2.Lines.Add(spaces + ' '+ jsPair.JsonString.Value+ ': '+ jsPair.JsonValue.Value);
if (jsPair.JsonValue is TJsonArray) then
begin
spaces := spaces + ' ';
if (jsPair.JsonValue.ToString).Contains(':') then
begin
ParseJson2('{"'+jsPair.JsonString.Value+'":'+jsPair.JsonValue.ToString+'}', jsPair.JsonString.Value);
end else begin
aos := (jsPair.JsonValue.ToString).Split([','], 99);
for j := low(aos) to High(aos) do
begin
sValue := StringReplace(aos[j], '[', '', [rfReplaceAll]);
sValue := StringReplace(sValue, ']', '', [rfReplaceAll]);
sValue := StringReplace(sValue, '"', '', [rfReplaceAll]);
if trim(sValue) <> '' then Memo2.Lines.Add(spaces+spaces+sValue);
end;
end;
spaces := copy(spaces,1,length(spaces)-3);
end;
end;
end;
finally
jsv.Free();
end;
except
on E: Exception do
Memo2.Lines.Add(E.ClassName+ ': '+ E.Message);
end;
end;
Delphi 10.2 Tokyo成功解析了JSON,所以我假设它是XE4中的一个错误。您应该使用调试器来确定它的确切位置。 –