http://json.codeplex.com/
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
if(code["a"]!=null){
...
}
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
这两个了具体不知道怎么写呀,我要解析这个网址的json并拿到数据,怎么操作呀???非常感谢
using Newtonsoft.Json;
private string Getjson()
{
string getUrl = "http://172.16.0.145/jsjApi/?action=BigdataList";
WebRequest webReq = WebRequest.Create(getUrl);
WebResponse webResp = webReq.GetResponse();
Stream stream = webResp.GetResponseStream();
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
string html = sr.ReadToEnd();
sr.Close();
stream.Close();
return html;
}
string json =Getjson();
Hashtable js = JsonConvert.DeserializeObject(json, typeof(Hashtable)) as Hashtable;
string dataString = js["test"].ToString();
......
这样是可以的,但是我要把解析拿到的TitleName显示做一个分页绑定到checkedListBox1上面,具体该怎么写呀???求帮助呀
using System;
using System.Net;namespace dosoft.App_Code
{
public class AddressHelper
{
public static string PostIP = "http://ip.taobao.com/service/getIpInfo.php?ip=";
public static AddressInfo GetAddress(string ip)
{
var addr = "";
try
{
using (WebClient c = new WebClient())
{
string s = c.DownloadString(PostIP + ip);
addr = s;
}
return Newtonsoft.Json.JsonConvert.DeserializeObject<AddressInfo>(addr);
}
catch (Exception)
{
return new AddressInfo(){
code = 0,
data = new data() {
region="未知省份",
city = "未知城市"
}
};
}
}
}
[Serializable]
public class AddressInfo
{
public int code { get; set; }
public data data { get; set; }
}
[Serializable]
public class data
{
public string country { get; set; }
public string country_id { get; set; }
public string area { get; set; }
public string area_id { get; set; }
/// <summary>
/// 省份
/// </summary>
public string region { get; set; }
public string region_id { get; set; }
/// <summary>
/// 市
/// </summary>
public string city { get; set; }
public string city_id { get; set; }
public string county { get; set; }
public string county_id { get; set; }
public string isp { get; set; }
public string isp_id { get; set; }
public string ip { get; set; } }
}参考,,我这也是通过网站拿json数据并且转换的...大概差不多,自己理解下就好了同样的 我用的也是Newtonsoft.Json
var m=dosoft.App_Code.AddressHelper.GetAddress("");
messagebox.show("省="+m.data.region);
messagebox.show("省="+m.data.city);
我用这个方法已经取到了json数据并把它加入了checkedListBox1列表里面,现在我就是要把checkedListBox1显示的数据做一个分页让每页显示30条就行了,求帮助呀???急用啊
List<string> jsondata = new List<string> { };
private void Form1_Load(object sender, EventArgs e)
{
for(int i=0;i<100;i++)
{
jsondata.Add(i.ToString()); }
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{ checkedListBox1.Items.Clear();
int i=Convert.ToInt16(numericUpDown1.Value);
for (int j=i; j <i+ 30; j++)
{
checkedListBox1.Items.Add(jsondata[j].ToString());
}
}