How To Fix Circular Reference Error When Dealing With Json

前端 未结 2 696
离开以前
离开以前 2020-12-03 04:53

This question is a part of my original post here Get Data Into Extjs GridPanel

Below is my Controller that reads data from sql db and then I am trying to encode the

2条回答
  •  甜味超标
    2020-12-03 05:35

    I use the following tool for serializing and deserializing JSON:

    http://james.newtonking.com/pages/json-net.aspx

    It's very easy to use and very lightweight.

    While serializing we use this option:

    JsonConvert.SerializeObject(myObject, Formatting.Indented, 
                                new JsonSerializerSettings { 
                                       ReferenceLoopHandling = ReferenceLoopHandling.Ignore 
                                })
    

    It ignores circular references.

    Also json.net from newtonking is extremely fast.

    The other options is to use DTO's and map them via Automapper as mentioned by Diver.

    Edit: I suspect your store is wrong:

    var store = Ext.create('Ext.data.JsonStore', {      
            storeId: 'myData',
            reader: new Ext.data.JsonReader({
                root: 'myTable',
                fields: [{ name: 'Q1', type: 'int' },
                         { name: 'Q2', type: 'int' },
                         { name: 'Q3', type: 'int' },
                         { name: 'Q4', type: 'int' },
                         { name: 'Q5', type: 'int' },
                         { name: 'Improvements', type: 'string' },
                         { name: 'Comments', type: 'string'}]
            }),
    
            proxy: {
                 type: 'json',
                url: 'GridView/writeRecord'
            }    
    });  
    

提交回复
热议问题