比如定义一个类:

public class Lines
{
public string X1 { get; set; }
public string X2 { get; set; }
public string Y1 { get; set; }
public string Y2 { get; set; }
public string Z1 { get; set; }
public string Z2 { get; set; }
public string diameter { get; set; }
public string material { get; set; }
}

然后实例化了许多个Lines对象,存放在List<Lines>中。

如:

List<Lines> linesobj = new List<Lines>();
for (int i = 0; i < 20; i++)
{
linesobj.Add(new Lines(){X1=“1”, X2=“2”, Y1=“3”, Y2=“4”, Z1=”5“, Z2=”6“, diameter=”7“, material=”8”});
}

linesobj即为一个包含了20个Lines对象的数组。

下面将linesobj转化为json:

1.引用命名空间:using System.Web.Script.Serialization;

2.使用JavaScriptSerializer对象的Serialize方法,本例中为:

JavaScriptSerializer jss = new JavaScriptSerializer();
string myJson = jss.Serialize(linesobj);
return myJson;

此时的myJson即为转化后的json对象。

myJson[0]={"X1" : "1","X2" : "2"....};

myJson[1]={"X1" : "1","X2" : "2"....};

...

myJson[20]=...

C#中Object转化为json对象的更多相关文章

  1. 一般处理程序中 C#中对象转化为Json对象

    namespace: Newtonsoft.Json; context.Response.ContentType = "application/text"; 注:这里为什么不是 J ...

  2. 将XML文件中的内容转换为Json对象

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;u ...

  3. jQuery表单验证以及将表单序列化为json对象小练习

    jquery表单验证(非实时验证),同时,将表单序列化为json对象提交表单. <!DOCTYPE html> <html lang="en"> <h ...

  4. nodejs将JSON字符串转化为JSON对象

    如何将JSON字符串转化为JSON对象? JSON.parse(str)       JSON是javascript的一个内置对象,提供了转换JSON对象与字符串互相转换的方法: 问题来了,道理我都懂 ...

  5. 将表单序列化为JSON对象

    将表单序列化为JSON对象的工具方法: $(function() { //工具方法,可以将指定的表单中的输入项目序列化为JSON数据 $.fn.serializeJson = function() { ...

  6. 023-将表单序列化为json对象

    使用jQuery将表单序列化为json对象,其中serializeJson方法的名字任意,serializeArray()这个jQuery提供的方法.this指的就是谁调用了这个方法. $.fn.se ...

  7. jquery扩展方法(表单数据格式化为json对象)

    1.jquery扩展方法(表单数据格式化为json对象) <script type="text/javascript"> // 将表单数据序列化为一个json对象,例如 ...

  8. JSON字符串格式化为JSON对象

    根据项目需要,需要对json格式的字符串格式化为json对象,以下是解决方法: 参考文章:https://www.cnblogs.com/cailijuan/p/10150918.html

  9. javaScript中eval()方法转换json对象

    <script language="javascript"> var user = '{name:"张三",age:23,'+ 'address:{ ...

随机推荐

  1. ie浏览器下载附件中文乱码

    String llq = request.getHeader( "USER-AGENT" ).toLowerCase();Boolean isIE = false;if (llq. ...

  2. ymfx

    一.APIView 入口 在路由层执行as_view()方法 rest-framework/views.py/class APIView/def as_view() 可以看到,APIView继承了Dj ...

  3. HDU--2126 Buy the souvenirs(二维01背包)

    题目http://acm.hdu.edu.cn/showproblem.php?pid=2126 分析:有两个要求,一是计算最多可以选多少中纪念品:而是计算选最多纪念品的方案有多少种, 即统计最优方案 ...

  4. 关于mybatis对实体类参数绑定参数的问题

    dao层的代码: public interface SupplierMapper extends BaseMapper<SupplierDbo>{ /*List<SupplierDb ...

  5. ASP.NET MVC生命周期与管道模型

      先来熟悉下asp.net请求管道 1.当客户端发送http://localhost:80/home/index请求时 2.首先到达服务端的内核模块HTTP.SYS(它监听80端口),通过访问注册表 ...

  6. HZOI20190818模拟25题解

    题面:https://www.cnblogs.com/Juve/articles/11372379.html A:字符串 其实是CATALAN数水题... 和网格一毛一样:https://www.cn ...

  7. 转载:JVM内存分代策略

    Java虚拟机根据对象存活的周期不同,把堆内存划分为几块,一般分为新生代.老年代和永久代(对HotSpot虚拟机而言),这就是JVM的内存分代策略. 为什么要分代? 堆内存是虚拟机管理的内存中最大的一 ...

  8. Oracle时间日期处理方法

    https://www.cnblogs.com/plmm/p/7381496.html 1.用于截取年.月.日.时.分.秒 extract()函数 extract(year from sysdate) ...

  9. 2019-10-23-C#-从零开始写-SharpDx-应用-绘制基础图形

    title author date CreateTime categories C# 从零开始写 SharpDx 应用 绘制基础图形 lindexi 2019-10-23 21:16:35 +0800 ...

  10. UVAL3700

    Interesting Yang Hui Triangle 题目大意:杨辉三角第n + 1行不能整除p(p是质数)的数的个数 题解: lucas定理C(n,m) = πC(ni,mi) (mod p) ...