Adobe Document Generation API嵌套数组JSON调用报错排查
Adobe Document Generation API JSON结构报错问题
我用下面的JSON数据调用Adobe Document Generation API时出现报错,单独用第一个对象没问题,但用完整数组就报错,不确定JSON结构哪里有问题。
完整JSON数据:
[ { "OwnerID": "L001", "Properties": [ [ { "PropertyID": "P001", "Property Address": "12 St LA", "Rent": "300", "Bedroom ": "2 " } ], [ { "PropertyID": "P002", "Property Address": "3 St SA", "Rent": "450", "Bedroom ": "3 " } ] ] }, { "OwnerID": "L002", "Properties": [ [ { "PropertyID": "P003", "Property Address": "4 St SA", "Rent": "500", "Bedroom ": "4 " } ] ] }, { "OwnerID": "L003", "Properties": [ [ { "PropertyID": "P004", "Property Address": "20 St LA", "Rent": "400", "Bedroom ": "2 " } ] ] } ]
错误提示:
仅使用该JSON中的第一个对象时无报错,数据如下:
{ "OwnerID": "L001", "Properties": [ [ { "PropertyID": "P001", "Property Address": "12 St LA", "Rent": "300", "Bedroom ": "2 " } ], [ { "PropertyID": "P002", "Property Address": "3 St SA", "Rent": "450", "Bedroom ": "3 " } ] ] }
问题原因与解决方法
问题出在Properties字段的冗余嵌套上:你给的结构是数组套数组再套对象([[{}]]),Adobe Document Generation API处理多层嵌套数组时容易解析异常,尤其是当模板中需要遍历数组数据时,这种多余的嵌套会让API无法正确识别数据层级。
把Properties里的内层数组去掉,改成直接包含对象的一维数组即可,修正后的完整JSON如下:
[ { "OwnerID": "L001", "Properties": [ { "PropertyID": "P001", "Property Address": "12 St LA", "Rent": "300", "Bedroom ": "2 " }, { "PropertyID": "P002", "Property Address": "3 St SA", "Rent": "450", "Bedroom ": "3 " } ] }, { "OwnerID": "L002", "Properties": [ { "PropertyID": "P003", "Property Address": "4 St SA", "Rent": "500", "Bedroom ": "4 " } ] }, { "OwnerID": "L003", "Properties": [ { "PropertyID": "P004", "Property Address": "20 St LA", "Rent": "400", "Bedroom ": "2 " } ] } ]
内容的提问来源于stack exchange,提问作者jsbev
相关产品推荐
相关产品推荐

