Newtonsoft.Json取json字符串中的值得用法 看红色的部分就可以了

http://www.cnblogs.com/fierceeagle/p/3545615.html

<%@ WebHandler Language="C#" Class="AddShopOnly" %>

using System;
using System.Web;
using Newtonsoft.Json;//先引入这两个命名空间
using Newtonsoft.Json.Converters;
using System.Data;
using Redsz.DAO;
public class AddShopOnly : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";

string uid = context.Request["uid"];
string projectid = context.Request["projectid"];
string parme = GetJson(uid);
object obj = JsonConvert.DeserializeObject(parme);//obj   转换json格式的字符串为obj对象

//{ 
// status: 0, 
// message: "ok", 
// result: { 
// name: "江边城外•巫山烤全鱼亚运村店", 
// location: { 
// lng: 116.412347, 
// lat: 40.005328 
// }, 
// address: "朝阳区慧忠北路慧忠里123号楼(近北辰东路)", 
// telephone: "(010)64924119", 
// uid: "8ee4560cf91d160e6cc02cd7", 
// detail_info: { 
// tag: "美食 中餐馆 烤鱼 饭统北京 家人团聚 朋友聚会 烧烤 学生聚餐 二三人小聚 家庭团聚 生日PARTY 同事朋友聚会 亚运村店 川菜 适合大伙人 餐馆 川北凉粉 大拌菜 豆豉烤鱼 豆豉清江鱼 怪味清江鱼 会员卡商户 家常泡饼 家庭聚会 可以刷卡 麻辣烤鱼 免费停车 朋友聚餐 皮蛋豆腐 青椒皮蛋 情侣约会 商务宴请 跳水木耳 无线上网 香辣烤鱼 香辣清江鱼 休闲小憩 有无烟区", 
// detail_url: "http://api.map.baidu.com/place/detail?uid=8ee4560cf91d160e6cc02cd7&output=html&source=placeapi_v2", 
// type: "cater", 
// price: "63", 
// overall_rating: "5.0", 
// taste_rating: "5.0", 
// service_rating: "5.0", 
// environment_rating: "5.0", 
// image_num: "671", 
// comment_num: "1191", 
// favorite_num: "1851", 
// checkin_num: "45060", 
// shop_hours: "11:00-23:00" 
// } 
// } 
//}

Newtonsoft.Json.Linq.JObject js = obj as Newtonsoft.Json.Linq.JObject;//把上面的obj转换为 Jobject对象

Newtonsoft.Json.Linq.JToken model = js["result"];//取Jtoken对象     通过Jobject的索引获得到

string name=model["name"].ToString();//这里是取值
string lat = model["location"]["lat"].ToString();
string lng = model["location"]["lng"].ToString();
string address = model["address"] == null ? "" : model["address"].ToString();
string telephone = model["telephone"] == null ? "" : model["telephone"].ToString();

Newtonsoft.Json.Linq.JToken detail_info = js["result"]["detail_info"];

string price = detail_info["price"]==null?"":detail_info["price"].ToString();
string detail_url = detail_info["detail_url"].ToString();

string sql = "select count(id) as num from shops where shop_name='"+name+"' and projectid='"+projectid+"'; ";
int res=Convert.ToInt32(Data.getDataTableBySql(sql).Rows[0]["num"]);
if (res>0)
{
context.Response.Write("{\"success\":false,\"msg\":'此商家已添加到数据库'}");
}
else
{
string shop_pic = "暂无图片";//根据取到匹配的图片地址 再上传到我们自己的服务器

string createtime = DateTime.Now.ToString();
string insql = string.Format("INSERT shops (projectid,shop_name,shop_address,shop_tel,shop_pic,shop_applogo,shop_lat,shop_lng,createtime,status,state,isopen,upload_flag,active_flag)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')",
projectid, name, address, telephone, shop_pic, shop_pic, lat, lng, createtime, 1, 1, 1, 1, 1);
Data.RunSql(insql);
context.Response.Write("{\"success\":true,\"msg\":'添加成功'}");
}

}

public bool IsReusable
{
get
{
return false;
}
}

/// <summary>
/// 返回json格式的数据
/// </summary>
/// <param name="lat">纬度</param>
/// <param name="lng">经度</param>
/// <param name="radius">范围</param>
/// <param name="page_size">条数</param>
/// <returns></returns>
public string GetJson(string uid)
{

//http://api.map.baidu.com/place/v2/detail?uid=8ee4560cf91d160e6cc02cd7&ak=E4805d16520de693a3fe707cdc962045&output=json&scope=2
// http://api.map.baidu.com/place/v2/search?&query=%E5%B0%8F%E5%90%83%24%E7%90%86%E5%8F%91%E5%BA%97%24%E5%8C%BB%E9%99%A2%24%E7%94%9F%E6%B4%BB%E6%9C%8D%E5%8A%A1%24%E5%95%86%E5%BA%97%24%E8%B6%85%E5%B8%82%24%E4%BA%94%E9%87%91&location=<%=Request["lat"] %>,<%=Request["lng"] %>&radius=10000&output=json&ak=1735edad684487a9c4c82d1a94065632&page_size=10&page_num=0&scope=2 
string uri = string.Format("http://api.map.baidu.com/place/v2/detail?uid=" + uid + "&ak=1735edad684487a9c4c82d1a94065632&output=json&scope=2");
System.Net.WebClient wc = new System.Net.WebClient();
byte[] bResponse = wc.DownloadData(uri);
string strResponse = System.Text.Encoding.UTF8.GetString(bResponse);
// {"status":0,"result":{"location":{"lng":115.70974321125,"lat":32.13694390485},"precise":0,"confidence":14,"level":"\u533a\u53bf"}}

return strResponse;
}
}



Newtonsoft.Json取json字符串中的值得用法 这里是取的时候相关推荐

  1. Newtonsoft.Json取json字符串中的值得用法

    <%@ WebHandler Language="C#" class="AddShopOnly" %>using System; using Sys ...

  2. java数字取反_java中源码反码补码与取反的理解

    数字在计算机里是按照二进制来表示的. 箭头朝哪边就是朝哪边移动 补码,反码,和源码 负数原码转化为补码:符号位不变,数值位按位取反,末尾加一. 负数补码转化为原码:符号位不变,数值位按位取反,末尾加1 ...

  3. 取一个字符串中的数字

    400/(250w) =LEFT(A1,FIND("/",A1)-1) =400     FIND   函数 FIND 和 FINDB 用于在第二个文本串中定位第一个文本串,并返回 ...

  4. math的向上取整_Javascript中Math常用操作,向上取整、向下取整、四舍五入

    写在前面,最最常用几个方法: 绝对值:Math.abs(x) 最大值:Math.max([x[, y[, -]]]) 最小值:Math.min([x[, y[, -]]]) 随机值:Math.rand ...

  5. python矩阵所有元素取整_Python中如何对一个数值进行取整操作呢?

    摘要: 下文讲述Python中数值取整的方法分享,如下所示: 数值取整是我们处理数据常用的方法, 那么Python如何对数据进行取整操作呢? 下文将一一道来,如下所示: 实现思路: 方式1: math ...

  6. C语言大数阶乘取余,python中math模块常用函数介绍 取模(取余)取绝对值 求阶乘 求最大公约数最小公倍数 取对数 取根号 取幂(取次方) 取整函数 三角函数与反三角函数...

    前提:import math 两个常用常量 e = 2.718281828459045 pi = 3.141592653589793 >>> import math >> ...

  7. [转]C# 将类的内容写成JSON格式的字符串

    将类的内容写入到JSON格式的字符串中 本例中建立了Person类,赋值后将类中内容写入到字符串中 运行本代码需要添加引用动态库Newtonsoft.Json 程序代码: using System; ...

  8. java json 易用_Java中 Json的使用

    Java JSON 本章节我们将为大家介绍如何在 Java 语言中使用 JSON. 类库选择 Java中并没有内置JSON的解析,因此使用JSON需要借助第三方类库. 下面是几个常用的 JSON 解析 ...

  9. Java如何去除字符串中的HTML标签

    使用爬虫爬取网站数据,有时会将HTML相关的标签也一并获取,如何将这些无关的标签去除呢,往下看: 直接写个Test类: void deleteHtmlTags() {//定义字符串String htm ...

最新文章

  1. 元气骑士机器人修好后怎么用_《元气骑士》五大“难度”挑战,从手速到恶搞很嗨,还能解锁皮肤...
  2. share extension 不显示_高亮显示系统日志应该用什么命令
  3. LVS-DR模式原理
  4. sap.ca.scfld.md.ComponentBase.extend
  5. MVC是什么?(转载)
  6. opengl 如何加阴影_OpenGL + Qt: 3 - 旋转动画和键盘操纵
  7. Spring:笔记整理(1)——HelloWorld
  8. Linux编程(10)_进程通信
  9. #计算机网络#学习笔记-常用端口详解
  10. 信息系统项目管理---第九章 项目人力资源管理
  11. SDRAM 控制器(五)——数据读模块
  12. 电脑word文档页眉的横线怎么去掉
  13. 罗格斯的计算机科学博士奖学金,罗格斯大学计算机科学系
  14. RH413企业安全加固 第14章 配置系统日志
  15. 要学就学透彻!Spring Security 中 CSRF 防御源码解析
  16. Code Project精彩系列二
  17. Serenity Screenplay模式
  18. linux下的go富集分析,GO富集分析示例【华为云技术分享】
  19. XTerm 复制贴上
  20. Ubuntu更新-换源问题

热门文章

  1. 黑马头条项目 8.4 推荐系统接口定义
  2. 明天软考的童鞋进来顶起!!!
  3. 针对或者利用计算机网络实施,网络安全合规指引题库:针对或者利用计算机网络实施的犯罪,哪些公安机关不可以管辖?()...
  4. 无限网络性能 -- 移动网络优化
  5. spring源码分析01-(前期准备)spring核心原理解析和手写简易spring
  6. Notification Volume Control and Optimization System at Pinterest 小记
  7. 【OpenGL】十八、OpenGL 绘制多边形 ( 绘制 GL_POLYGON 模式多边形 )
  8. 激流勇进,在创新中求发展
  9. 2021年10月云短信报告出炉,腾讯云蝉联冠军
  10. SuperSocket客户端