Circular references are detected when an object of the JSON serialization type "ajax learning. datasetcomment + t_commentdatatable" is used.

Source: Internet
Author: User

I learned how to implement partial Ajax refresh paging today and encountered such an exception.

Circular references are detected when the serialization type is "ajax learning. datasetcomment + t_commentdatatable.

That is to say, because the data type is too complex, JSON cannot be converted to the data type. Now we need to store the data you want to convert in the form of class objects to solve this problem.

Today, I listed some of my code for your reference.

Pre-solution code

 

{
VaR adapter = new t_commenttableadapter ();
String pagenum = context. request ["pagenum"]; int ipagenum = convert. toint32 (pagenum); var DATA = adapter. getpageddata (ipagenum-1) * 10 + 1, ipagenum * 10 );
Javascriptserializer JSS = new javascriptserializer (); // serialized object in Javascript
Context. response. Write (JSS. serialize (data); // output to the page
}

Code after solution

  

{    var data = adapter.GetPagedData((iPageNum - 1) * 10 + 1, iPageNum * 10);     List<Comments> list=new List<Comments> ();     foreach(var row in data)     {         list.Add(new Comments() { Id = (int)row.Id, IP = row.IP, Msg = row.Msg, PostDate = row.PostDate, });     }     JavaScriptSerializer jss = new JavaScriptSerializer();     context.Response.Write(jss.Serialize(list));}

Public class comments
{
Public int ID {Get; set ;}
Public String IP {Get; set ;}
Public String MSG {Get; set ;}
Public String postdate {Get; set ;}
}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.