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

本实例使用的基站定位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
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值