3 回答

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超3個(gè)贊
我建議您使用Nuget Package 上提供的 C# NewtonSoft Json Package。
你可以這樣做:
var resultList = new List<SearchGoods>();
和:
resultList.Add(obj);
最后只返回:
return JsonConvert.SerializeObject(resultList);
它應(yīng)該給你正確的結(jié)果。

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊
我認(rèn)為你的方法類型應(yīng)該是 JsonResult 像這樣
public JsonResualt GetAllGoodInCat([FromBody]GoodsCatId goodsCatId){}
在返回方法中,您應(yīng)該像這樣返回 Json
return Json(model, JsonRequestBehavior.AllowGet);

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊
您的 json 格式無效,這就是您收到所有這些錯(cuò)誤的原因。你有 "" 包圍了你的 json 的每個(gè)對(duì)象和數(shù)組。只需刪除它,你就可以開始了。
我已經(jīng)清理了你的 json :
[
{
"id": 2,
"name": "???????",
"image": "test.png",
"subLevelOne": [
{
"id": 11,
"parentId": 2,
"name": "??????",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 25,
"parentId": 11,
"name": "?????? ????",
"image": "testmy.png"
}
]
}
]
},
{
"id": 2,
"name": "???????",
"image": "test.png",
"subLevelOne": [
{
"id": 12,
"parentId": 2,
"name": "??????",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 26,
"parentId": 12,
"name": "?????? ?? ???",
"image": "testmy.png"
}
]
}
]
},
{
"id": 3,
"name": "????? ?????",
"image": "test.png",
"subLevelOne": [
{
"id": 9,
"parentId": 3,
"name": "????",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 22,
"parentId": 9,
"name": "???? ????",
"image": "testmy.png"
}
]
}
]
},
{
"id": 3,
"name": "????? ?????",
"image": "test.png",
"subLevelOne": [
{
"id": 10,
"parentId": 3,
"name": "????",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 24,
"parentId": 10,
"name": "???? ????",
"image": "testmy.png"
}
]
}
]
},
{
"id": 4,
"name": "??????",
"image": "test.png",
"subLevelOne": [
{
"id": 13,
"parentId": 4,
"name": "????",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 27,
"parentId": 13,
"name": "???? ????",
"image": "testmy.png"
}
]
}
]
},
{
"id": 4,
"name": "??????",
"image": "test.png",
"subLevelOne": [
{
"id": 14,
"parentId": 4,
"name": "??????",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 28,
"parentId": 14,
"name": "?????? ????",
"image": "testmy.png"
}
]
}
]
},
{
"id": 5,
"name": "????? ? ???? ?????",
"image": "test.png",
"subLevelOne": [
{
"id": 15,
"parentId": 5,
"name": "?? ????",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 29,
"parentId": 15,
"name": "?? ????",
"image": "testmy.png"
}
]
}
]
},
{
"id": 5,
"name": "????? ? ???? ?????",
"image": "test.png",
"subLevelOne": [
{
"id": 16,
"parentId": 5,
"name": "?????",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 30,
"parentId": 16,
"name": "????? ?????",
"image": "testmy.png"
}
]
}
]
},
{
"id": 6,
"name": "????? ? ???????",
"image": "test.png",
"subLevelOne": [
{
"id": 17,
"parentId": 6,
"name": "??????",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 31,
"parentId": 17,
"name": "?????? ????",
"image": "testmy.png"
}
]
}
]
},
{
"id": 6,
"name": "????? ? ???????",
"image": "test.png",
"subLevelOne": [
{
"id": 18,
"parentId": 6,
"name": "??????",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 32,
"parentId": 18,
"name": "?????? ??????",
"image": "testmy.png"
}
]
}
]
},
{
"id": 7,
"name": "?????? ? ????????",
"image": "test.png",
"subLevelOne": [
{
"id": 19,
"parentId": 7,
"name": "???",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 33,
"parentId": 19,
"name": "??? ????",
"image": "testmy.png"
}
]
}
]
},
{
"id": 7,
"name": "?????? ? ????????",
"image": "test.png",
"subLevelOne": [
{
"id": 20,
"parentId": 7,
"name": "????",
"image": "mytest.png",
"subLevelTwo": [
{
"id": 34,
"parentId": 20,
"name": "???? ????",
"image": "testmy.png"
}
]
}
]
}
]
希望能幫到你!
- 3 回答
- 0 關(guān)注
- 403 瀏覽
添加回答
舉報(bào)