这次的json成功了,没有感觉的快
返回来的值
Quotation
[{"name":"else","age":"26"},{"name":"alive","age":"27"},{"name":"kanu","age":"23"}]
using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using JSONSharp.Values;
using JSONSharp.Collections;
using System.Collections.Generic;
using JSONSharp;
namespace testjson
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class jsondata : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
userinfo usif = new userinfo();
List<JSONValue> jsonlist = new List<JSONValue>();
// Dictionary<JSONStringValue, JSONValue> jsonNameValuePairs = new Dictionary<JSONStringValue, JSONValue>();
string where = "1=1 ";
DataSet ds = usif.GetList(where);
context.Response.Write("[");
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
Dictionary<JSONStringValue, JSONValue> jsonNameValuePairs = new Dictionary<JSONStringValue, JSONValue>();
JSONStringValue jsv_name_Business = new JSONStringValue("name");
JSONStringValue jsv_value_Business = new JSONStringValue(ds.Tables[0].Rows[i]["name"].ToString());
jsonNameValuePairs.Add(jsv_name_Business, jsv_value_Business);
JSONStringValue jsv_name_Age = new JSONStringValue("age");
JSONStringValue jsv_value_Age = new JSONStringValue(ds.Tables[0].Rows[i]["age"].ToString());
jsonNameValuePairs.Add(jsv_name_Age, jsv_value_Age);
JSONObjectCollection jsonObjectCollection = new JSONObjectCollection(jsonNameValuePairs);
context.Response.Write(jsonObjectCollection.ToString());
if (i < ds.Tables[0].Rows.Count - 1)
{
context.Response.Write(",");
}
}
context.Response.Write("]");
//JSONObjectCollection jsonObjectCollection = new JSONObjectCollection(jsonNameValuePairs);
//context.Response.Write(jsonObjectCollection.ToString());
//context.Response.Write(jsonObjectCollection.PrettyPrint());
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using JSONSharp.Values;
using JSONSharp.Collections;
using System.Collections.Generic;
using JSONSharp;
namespace testjson
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class jsondata : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
userinfo usif = new userinfo();
List<JSONValue> jsonlist = new List<JSONValue>();
// Dictionary<JSONStringValue, JSONValue> jsonNameValuePairs = new Dictionary<JSONStringValue, JSONValue>();
string where = "1=1 ";
DataSet ds = usif.GetList(where);
context.Response.Write("[");
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
Dictionary<JSONStringValue, JSONValue> jsonNameValuePairs = new Dictionary<JSONStringValue, JSONValue>();
JSONStringValue jsv_name_Business = new JSONStringValue("name");
JSONStringValue jsv_value_Business = new JSONStringValue(ds.Tables[0].Rows[i]["name"].ToString());
jsonNameValuePairs.Add(jsv_name_Business, jsv_value_Business);
JSONStringValue jsv_name_Age = new JSONStringValue("age");
JSONStringValue jsv_value_Age = new JSONStringValue(ds.Tables[0].Rows[i]["age"].ToString());
jsonNameValuePairs.Add(jsv_name_Age, jsv_value_Age);
JSONObjectCollection jsonObjectCollection = new JSONObjectCollection(jsonNameValuePairs);
context.Response.Write(jsonObjectCollection.ToString());
if (i < ds.Tables[0].Rows.Count - 1)
{
context.Response.Write(",");
}
}
context.Response.Write("]");
//JSONObjectCollection jsonObjectCollection = new JSONObjectCollection(jsonNameValuePairs);
//context.Response.Write(jsonObjectCollection.ToString());
//context.Response.Write(jsonObjectCollection.PrettyPrint());
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
Welcome to Visual Studio 2010
自娱自乐的不是电影奖,而是寂寞
