JSON.Net Self referencing loop detected

前端 未结 11 853
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 04:18

I have a mssql database for my website within 4 tables.

When I use this:

public static string GetAllEventsForJSON()
{
    using (CyberDBDataContext d         


        
11条回答
  •  半阙折子戏
    2020-11-28 04:53

    Sometimes you have loops becouse your type class have references to other classes and that classes have references to your type class, thus you have to select the parameters that you need exactly in the json string, like this code.

    List oficinas = new List();
    oficinas = /*list content*/;
    var x = JsonConvert.SerializeObject(oficinas.Select(o => new
                {
                    o.IdOficina,
                    o.Nombre
                }));
    

提交回复
热议问题