我的 ApiController 方法以这种格式返回 JSON:
"[{\"Category\":{\"CategoryType\":{\"Categories\":[{\"Client\":{\"Categories\":[{\"CategoryType\":{\"Categories\":[{\"Controls\":[],\"Risks\":[{\"Controls\":[],\"PCRMaps\":[],\"Id\":3,\"Title\":\"Risk with ID\",\"Description\":\"Test\",\"CategoryId\":80, etc etc
我有 AngularJS 代码从这个 JSON 对象呈现一个下拉列表,如下所示:
<select ng-model="newRisk.ClientId" id="ddlClient" name="ddlClient">
<option></option>
<option ng-repeat="client in clients" value="{{client.Id}}">{{client.Name}}</option>
</select>
但我得到的错误似乎表明这个 JSON 被不正确地解释:
Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed.
Use 'track by' expression to specify unique keys.
Repeater: client in clients track by client.Id,
Duplicate key: undefined, Duplicate value: "["
让我失望的是最后一行 - 重复值“[”
这是控制器代码。很简单:
[HttpGet]
public string GetAll()
{
return JsonConvert.SerializeObject(clientRepo.GetAll(),
Formatting.Indented,
new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
}
在返回 JSON 对象之前,是否需要采取额外的格式化步骤?