首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

ashx c# 输出多个json 数组解决办法

2013-04-20 
ashx c# 输出多个json 数组connection new MySqlConnection(connectionString)MySqlCommand myCommand

ashx c# 输出多个json 数组

  connection = new MySqlConnection(connectionString);
                MySqlCommand myCommand = new MySqlCommand();
                myCommand.Connection = connection;
                myCommand.CommandType = System.Data.CommandType.Text;
                string sql = "select DISTINCT package_category from all_shop where shopname =?shopname and package_category !=''";
                myCommand.CommandText = sql;
                myCommand.Parameters.Add(new MySqlParameter("shopname", MySqlDbType.VarChar, 255)).Value = shopname;
                MySqlDataReader myReader = null;
                connection.Open();
                myReader = myCommand.ExecuteReader();

                System.Collections.ArrayList people = new System.Collections.ArrayList();

                while (myReader.Read())
                {
                    Person p1 = new Person();
                    p1.package_category = myReader["package_category"].ToString();
                    people.Add(p1);
                }

                connection.Close();
                Person[] ps = (Person[])people.ToArray(typeof(Person));
                context.Response.ContentType = "text/plain";
                System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
                string json = jss.Serialize(ps);//json 
                context.Response.Write(json);


想输出2个数组(sql select 不一样) , 但目前只会写一个的,愿好心人帮帮忙,给个简单例子,教导教导 ! 感恩!
[解决办法]
拼接一下就行了嘛
------解决方案--------------------


先分别得到JSON然后
json= string.Format("[{0},{1}]",json1,json2);
[解决办法]
这样更直观一点。
你只要拼成类似的格式,前台就可以灵活的处理
ashx c# 输出多个json 数组解决办法
[解决办法]
以数组的样式


var jsonstr = "[{name:'fish',age:18},{address:'china'}]";
var arrobject = eval('('+jsonstr+')');
console.log(arrobject[1].address);



输出:china

热点排行