jp1017

jp1017

0个粉丝

78

问答

0

专栏

9

资料

jp1017  发布于  2015-08-25 20:35:16
采纳率 0%
78个问答
2850

JsonReader解析json数据失败求解

本帖最后由 jp1017 于 2015-8-25 20:36 编辑

        最近自己搞了个博客,后面和大家分享。
       
        今天遇到个问题,JsonReader解析json失败,麻烦大家看下,给解答下:

        要解析的json数据是这个:

        [code][{id:56, title:"xxx", timelength:99}, {id:22, title:"@@@", timelength:444}][/code]

        我的解析代码:
       
        [code]                //json解析之JsonReader
                JsonReader reader = new JsonReader(new InputStreamReader(inStream));
                reader.beginArray();
                while (reader.hasNext()) {
                        reader.beginObject();
                        while (reader.hasNext()) {
                                String keyName = reader.nextName();
                                if ("id".equals(keyName)) {
                                        id = reader.nextInt();
                                }else if ("title".equals(keyName)) {
                                        title = reader.nextString();
                                }else if ("timelength".equals(keyName)) {
                                        timelength = reader.nextInt();
                                }else {
                                        reader.skipValue();
                                }
                        }
                        reader.endObject();
                        newses.add(new News(id, title, timelength));
                }
                reader.endArray();
                return newses;[/code]

        为什么执行到第六行就执行不下去了呢?求解
我来回答
回答1个
时间排序
认可量排序

Heguming

0个粉丝

8

问答

0

专栏

6

资料

Heguming 2015-08-26 16:12:30
认可0
其一,是否捕捉异常,
其二,建议替换InputStreamReader为StringReader
Over
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区