开发者社区> 问答> 正文

new JSONObject(String)为什么报错?报错

用到的jar包如下:

  1. commons-lang.jar
  2. commons-beanutils.jar
  3. commons-collections.jar
  4. commons-logging.jar 
  5. ezmorph.jar
  6. json-lib-2.2.2-jdk15.jar

展开
收起
爱吃鱼的程序员 2020-06-10 10:04:00 1131 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    话说字符串类型的不用引号真的好吗?回复<aclass='referer'target='_blank'>@深蓝浅爱:哦哦,原来是构造方法用错的原因,用JSONObject.from...那个方法吧用了<divclass='ref'>

    引用来自“杨延庆”的评论

    你的用户,日期格式这些值一个引号都没有,当然会有问题。

    你这是什么JSON包?光发个代码怎么解决问题?

    另外,newJSONObject(String)没有这个构造方法啊

    你应该是传MAP进去才对

    <imgsrc="http://static.oschina.net/uploads/space/2015/1211/112252_9xND_119807.png"alt="">

    我试试去<divclass='ref'>

    引用来自“一堆BUG”的评论

    你这是什么JSON包?光发个代码怎么解决问题?

    另外,newJSONObject(String)没有这个构造方法啊

    你应该是传MAP进去才对

    <imgsrc="http://static.oschina.net/uploads/space/2015/1211/112252_9xND_119807.png"alt="">

    你的用户,日期格式这些值一个引号都没有,当然会有问题。

    <atarget="_blank"rel="nofollow">http://grepcode.com/file/repo1.maven.org/maven2/net.sf.json-lib/json-lib/2.2.2/net/sf/json/JSONObject.java?av=f

    从API来看,你应该使用

    <preclass="brush:java;toolbar:true;auto-links:false;">JSONObjectjsonObj=JSONObject.fromObject("...");



    <divclass='ref'><divclass='ref'>

    引用来自“杨延庆”的评论

    你的用户,日期格式这些值一个引号都没有,当然会有问题。

    你用的是<spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">json-lib-2.2.2也就是net.sf的.

    <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">这个json库不是这么用的.

    <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">这样:

    <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">JSONObjectjson=JSONObject.fromObject(jsonStr...);

    <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">

    赶紧采纳答案给分吧!

    key,和字符串value加上双引号应该没问题吧

    <preclass="brush:java;toolbar:true;auto-links:false;">JSONObjectjson=newJSONObject("{"name":"user"}");if(json.has("name")){System.out.println(json.get("name"));}



    2020-06-10 10:04:17
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多