1
에서 ASP.NET MVC 모델을 직렬화 이것은 내 컨트롤러내가 JSON으로 모델을 직렬화 할이</p> <pre><code>public class Category : BaseFieldsTables { public ICollection<Category> Categories { get; set; } public Category Parent { get; set; } public int? ParentId { get; set; } } </code></pre> <p>같은 모델을 가지고 JSON
var categories =
_efCategory.List().ToList().
ToList().
Select(x => new {id = x.Id, title = x.Name, children = x.Parent});
string output = JsonConvert.SerializeObject(categories, Formatting.Indented,
new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects
});
return Json(output.Replace, JsonRequestBehavior.AllowGet);
하지만 나는이 결과를 얻을 수
"[\r\n {\r\n \"$id\": \"1\",\r\n \"id\": 1,\r\n \"title\": \"News\",\r\n \"children\": null\r\n },\r\n {\r\n \"$id\": \"2\",\r\n \"id\": 2,\r\n \"title\": \"2012\",\r\n \"children\":
{\r\n \"$id\": \"3\",\r\n \"Categories\": [\r\n {\r\n \"$id\":
하지만 난 나무를 위해 이것을 사용하려면 내가 [ { "$ ID가"이 오류 catch되지 않은 잘못된 데이터 형식 얻을 : "1", "ID": 2, "제목": "뉴스", 을 "children": null }, –
즉, JSON을 잘못 구문 분석하고 있음을 의미합니다. 더 많은 코드를 게시해야합니다 ... JSON 자체가 정확합니다. –
이 "$ id": "13", "id": 12, –