Self referencing loop in Json.Net JsonSerializer from custom JsonConverter (Web API)

前端 未结 7 1262
温柔的废话
温柔的废话 2020-12-16 09:28

The project is an Asp.Net Web API web service.

I have a type hierarchy that I need to be able to serialize to and from Json, so I have taken the code from this SO: H

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 09:52

    I just had the same plroblem with Parent/Child collections and found that post which has solved my case. I Only wanted to show the List of parent collection items and didn't need any of the child data, therefore i use the following and it worked fine:

    JsonConvert.SerializeObject(ResultGroups, Formatting.None,
                            new JsonSerializerSettings()
                            { 
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            });
    

    it also referes to the Json.NET codplex page at:

    http://json.codeplex.com/discussions/272371

提交回复
热议问题