如何将类对象返回给json对象 [英] How do I return a class object to a json object

查看:74
本文介绍了如何将类对象返回给json对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个类对象返回给一个json对象。

我该怎么做?

  public   static  JsonReturn getJson()
{
...
List< Table1> thelist = new List< Table1>();
表1 tb1 = new Table1();
tb1.Id = 1 ;
tb1.col1 = 1;
tb1.col2 = 2;
tb1.col3 = 3;
thelist.Add(tb1);
return Json(thelist,???);
}

解决方案

尝试

列表与LT;表1> thelist =  new  List< table1>(); 
表1 tb1 = new Table1();
tb1.Id = 1 ;
tb1.col1 = 1;
tb1.col2 = 2;
tb1.col3 = 3;
thelist.Add(tb1);
var json = new JavaScriptSerializer()。Serialize(thelist);
Console.WriteLine(json); < / table1 > < / table1 >


I want to return a class object to a json object.
How do I do that?

public static JsonReturn getJson()
{
    ...
    List<Table1> thelist = new List<Table1>();
    Table1 tb1 = new Table1();
    tb1.Id = 1;
    tb1.col1 = "1";
    tb1.col2 = "2";
    tb1.col3 = "3";
    thelist.Add(tb1);
    return Json(thelist, ???);
 }

解决方案

Try

List<table1> thelist = new List<table1>();
Table1 tb1 = new Table1();
tb1.Id = 1;
tb1.col1 = "1";
tb1.col2 = "2";
tb1.col3 = "3";
thelist.Add(tb1);
var json = new JavaScriptSerializer().Serialize(thelist);
Console.WriteLine(json);</table1></table1>


这篇关于如何将类对象返回给json对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆