Method 1: splice JSON format in front-end JavaScript, array format (or set) [{},{}], object format {"":"","": ""} {Name :{"":""}}
Use List <t> listwebsituser = newtonsoft in the background. JSON. jsonconvert. deserializeobject (JSON, typeof (list <t>) as list <recommedwebsiteuser>; here, JSON is a set, so it is converted to a generic list <t>
Listwebsituser is a generic set of recommedwebsiteuser. In this way, the JSON string spliced at the front end is converted to a list of collections. <t>
[Serializable]
Class recommedwebsiteuser
{
Private string userid;
Public String userid
{
Get {return userid ;}
Set {userid = value ;}
}
Private string realname;
Public String realname
{
Get {return realname ;}
Set {realname = value ;}
}
}
To convert list <t> to JSON:
// The first method. This method requires reference of system. runtime. serialization. dll and system. servicemodel. Web. dll.
Datacontractjsonserializer serializer = new datacontractjsonserializer (listwebsituser. GetType ());
// Define a stream to store serialized content
Stream stream = new memorystream ();
Serializer. writeobject (stream, listwebsituser );
// Read stream data as a string from start to end and return
Stream. Position = 0;
Streamreader = new streamreader (Stream );
String json3 = streamreader. readtoend ();
// Method 2
String json1 = newtonsoft. JSON. jsonconvert. serializeobject (listwebsituser );
The two methods must mark the class as a serialized class.