For example, define a class:
Public classLines { Public stringX1 {Get;Set; } Public stringX2 {Get;Set; } Public stringY1 {Get;Set; } Public stringY2 {Get;Set; } Public stringZ1 {Get;Set; } Public stringZ2 {Get;Set; } Public stringdiameter {Get;Set; } Public stringMaterial {Get;Set; } }
A number of Lines objects are then instantiated and stored in the list<lines>.
Such as:
New List<lines>(); for (int0; i++) { linesobj. ADD (new Lines () {x1= "1", x2= "2", y1= "3", y2= "4", z1= " 5", z2="6", diameter="7", material="8"});
Linesobj is an array that contains 20 lines objects.
The following translates linesobj into JSON:
1. Reference namespaces: Using System.Web.Script.Serialization;
2. Use the Serialize method of the JavaScriptSerializer object, in this case:
New JavaScriptSerializer (); string Myjson = JSS. Serialize (linesobj); return Myjson;
The Myjson at this point is the converted JSON object.
myjson[0]={"X1": "1", "X2": "2" ....};
myjson[1]={"X1": "1", "X2": "2" ....};
...
Myjson[20]= ...
Convert object to JSON object in C #