方式一 !("key" in obj) 
方式二 obj.hasOwnProperty("key")  //obj为json对象。

实例:

        var jsonworld_pose = JSON.parse(data[0].world_pose);
var jsonorientation = jsonworld_pose.orientation; //次处可能为undefined
var jsonposition = jsonworld_pose.position;//次处可能为undefined if (jsonworld_pose.hasOwnProperty("orientation")) {//使用时先进行判断
$("#orientation-w").html(jsonorientation.w);
$("#orientation-x").html(jsonorientation.x);
$("#orientation-y").html(jsonorientation.y);
$("#orientation-z").html(jsonorientation.z);
} if (jsonworld_pose.hasOwnProperty("position")) {
$("#position-x").html(jsonposition.x);
$("#position-y").html(jsonposition.y);
$("#position-z").html(jsonposition.z);
}

JS中判断JSON数据是否存在某字段的方法 JavaScript中判断json中是否有某个字段的更多相关文章

  1. js跨域请求数据的3种常用的方法

    由于js同源策略的影响,当在某一域名下请求其他域名,或者同一域名,不同端口下的url时,就会变成不被允许的跨域请求.那这个时候通常怎么解决呢,对此菜鸟光头我稍作了整理:1.JavaScript   在 ...

  2. Spring MVC中传递json数据时显示415错误解决方法

    在ajax中设置 ContentType为'application/json;charset=utf-8' 传递的data类型必须是json字符串类型:{“key”:"value" ...

  3. FOR XML PATH做为数据表中单列或者多列的字符串拼接的方法,放到一列中去,很好用。

    先看看自己弄得例子,SELECT sName+',',hoppy+','  FROM student2 where hoppy='游泳' FOR XML PATH('')--PATH后面跟的是行标题, ...

  4. 只要三步!阿里云DLA帮你处理海量JSON数据

    概述 您可能有大量应用程序产生的JSON数据,您可能需要对这些JSON数据进行整理,去除不想要的字段,或者只保留想要的字段,或者仅仅是进行数据查询. 那么,利用阿里云Data Lake Analyti ...

  5. js读取json数据(php传值给js)

    <?php $array =array('fds','fdsa','fdsafasd');  // json_encode($array); ?> <html> <hea ...

  6. Android(java)学习笔记208:Android中操作JSON数据(Json和Jsonarray)

    1.Json 和 Xml       JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的 ...

  7. URL中传递JSON数据

    有关于JSON如何在前后之间进行传递,转换成对象等操作,请查看  C#Json数据交互   (这篇文章主要介绍了如何转化Json格式的数据,以及如何使用) 我们在URL中传递数据一般都是 XX.asp ...

  8. Android(java)学习笔记151:Android中操作JSON数据(Json和Jsonarray)

    1.Json 和 Xml       JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的 ...

  9. 如何在Crystal Portlet中正确返回JSON数据给AJAX请求?

    当Crystal Portlet中需要采用Ajax请求,并让后台返回Json数据时,如何才能正确.方便的返回Json数据呢? 以下两种方法均可: 方法一:Ajax请求时,采用RenderURL,对应P ...

随机推荐

  1. C++中的new与delete总结

    1. operator new.operator delete与new.delete操作符的区别: operator new的作用类似于malloc,负责分配内存:operator delete的作用 ...

  2. Ubuntu装机必备

    sudo apt-get install rar unrar p7zip* sudo apt-get install tree sudo apt-get install wine sudo apt-g ...

  3. (原)linux 编译 lwqq

    1.安装工具 apt-get install automake apt-get install autoconf apt-get install libtool apt-get install lib ...

  4. java_jdbc_batch处理_主键id获取

    //create1 速度较慢,create2较快,但是要根据数据库不同来决定 //ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_ ...

  5. Advanced Configuration Tricks

    Advanced Configuration Tricks Configuration of zend-mvc applications happens in several steps: Initi ...

  6. 去model化开发

    前言 去model化是一种框架设计上的做法,其中的model并不是指架构中的model层,套用Casa大神博客中的原文就是: model化就是使用数据对象,去model化就是不使用数据对象. 常见的去 ...

  7. org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge]

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto ...

  8. Cummins INSITE locked and ask for verification code

    Some Cummins INSITE users turn to our engineer with a same question: INSITE has detected an invalid ...

  9. 深入理解计算机系统第二版习题解答CSAPP 2.15

    只使用位级运算和逻辑运算,编写一个C表达式,它等价于x==y.换句话说,当x和y相等时它将返回1,否则就返回0. !(x ^ y)

  10. [转载]“java.sql.SQLException:指定了无效的 Oracle URL”

    原文地址:"java.sql.SQLException:指定了无效的 Oracle URL"作者:康愚 昨天晚上用MyEclipse连接Oracle,出现了" java. ...