c# 编写基站定位API接口解析

来源:互联网 发布:手机乐园java手机版 编辑:程序博客网 时间:2024/05/18 18:53

本实例使用的基站定位API接口网址如下:
LBS数据仓库http://www.cellocation.com/interfac/

这边采用的基站定位API接口返回数据格式是JSON格式,所以在C#里面应用Newtonsoft.Json.dll控件,下载地址如下:
Newtonsoft.Json.dll控件下载地址http://download.csdn.net/detail/zqrhzyj/9818829

界面如下:
这里写图片描述
这里使用的是GET请求,示例如下:

string strURL = "http://api.cellocation.com/cell/?mcc=460&mnc=1&lac="+lac1.ToString()+"&ci="+cid1.ToString()+"&output=json";System.Net.HttpWebRequest request;// 创建一个HTTP请求request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);//request.Method="get";System.Net.HttpWebResponse response;response = (System.Net.HttpWebResponse)request.GetResponse();System.IO.StreamReader myreader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8);string responseText = myreader.ReadToEnd();myreader.Close();

新建一个lbs类,代码如下:

 class lbs    {        //经纬度信息类        /// <summary>        /// 经度        /// </summary>        public double lon { get; set; }        /// <summary>        /// 纬度        /// </summary>        public double lat { get; set; }        /// <summary>        /// 地址        /// </summary>        public string address { get; set; }    }

解析返回的JSON数据

lbs lbs1 = Newtonsoft.Json.JsonConvert.DeserializeObject<lbs>(responseText);this.texcard.Text = Convert.ToInt32(row[1]).ToString();this.texlong.Text = lbs1.lon.ToString();this.texlat.Text = lbs1.lat.ToString();this.texadr.Text = lbs1.address.ToString();
0 0
原创粉丝点击