开发者社区> 问答> 正文

关于String转换json报错 ?报错

String rs="[ { "name": "UserName", "displayName": "Username"},{ "name": "WeeksSinceRegistration", "displayName": "Weeks Since Registration" }]";

A JSONObject text must begin with '{' at character 1 of [ame of the这是报错息

JSONObject obj = JSONObject.fromObject(rs);
List> map = (List>) JSONObject.toBean(obj, List.class);

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

    报错信息说了JSON对象需要以'{'字符开头

    先添加json架包

    Stringrs="[{'name':'UserName','displayName':'Username'},{'name':'WeeksSinceRegistration','displayName':'WeeksSinceRegistration'}]";JSONArrayarr=JSONArray.fromObject(rs);for(Objecto:arr){JSONObjectb=JSONObject.fromObject(o);System.out.println(b.get("name"));}```

    15599020164

    1.json用JSONObject来进行解析
    2.json数组用JSONArray来进行解析

    你的是数组,所以需要用JSONArray进行解析,希望能帮到你...

    楼上说的对,你的是数组类的json。用jsonarray解析。

    楼主,你这是json数组请使用JSONArray来解析

    2020-06-23 01:29:43
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

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

相关实验场景

更多