救急啊.....
在写新浪微博客户端时遇到了问题,用JsonReader解析微博返回数据时显示如下错误
java.lang.IllegalStateException: Expected a name but was STRING at line 1 column 47
相关代码如下:
public long getWeiBoId(String JsonData){
long weiboId = 0;
try{
JsonReader reader = new JsonReader(new StringReader(JsonData));
reader.beginObject();
while(reader.hasNext()){
String tagName = reader.nextName();
if(tagName.equals("id")){
weiboId = reader.nextLong();
}
}
reader.endObject();
}catch(Exception e){
e.printStackTrace();
}
return weiboId;
}
返回的Json字符串如下:
{"created_at":"Fri Aug 17 14:16:04 +0800 2012","id":3480016971496941,"mid":"3480016971496941","idstr":"3480016971496941","text":"Json ","source":"<a href=\"http://open.t.sina.com.cn\" rel=\"nofollow\">未通过审核应用</a>","favorited":false,"truncated":false,"in_reply_to_status_id":"","in_reply_to_user_id":"","in_reply_to_screen_name":"","geo":null,"user":{"id":2049309993,"idstr":"2049309993","screen_name":"A_littlemore","name":"A_littlemore","province":"11","city":"8","location":"北京 海淀区","description":"","url":"","profile_image_url":"http://tp2.sinaimg.cn/2049309993/50/5614835694/1","profile_url":"u/2049309993","domain":"","weihao":"","gender":"m","followers_count":98,"friends_count":86,"statuses_count":83,"favourites_count":0,"created_at":"Sat Oct 29 13:27:35 +0800 2011","following":false,"allow_all_act_msg":false,"geo_enabled":true,"verified":false,"verified_type":-1,"allow_all_comment":true,"avatar_large":"http://tp2.sinaimg.cn/2049309993/180/5614835694/1","verified_reason":"","follow_me":false,"online_status":0,"bi_followers_count":36,"lang":"zh-cn"},"reposts_count":0,"comments_count":0,"mlevel":0,"visible":{"type":0,"list_id":0}}...经检测在解析完created_at后再次执行hasNext()时,reader内部的name属性为null....不知道是什么原因怎么解决呢,求各位大侠帮忙啊.....
在写新浪微博客户端时遇到了问题,用JsonReader解析微博返回数据时显示如下错误
java.lang.IllegalStateException: Expected a name but was STRING at line 1 column 47
相关代码如下:
public long getWeiBoId(String JsonData){
long weiboId = 0;
try{
JsonReader reader = new JsonReader(new StringReader(JsonData));
reader.beginObject();
while(reader.hasNext()){
String tagName = reader.nextName();
if(tagName.equals("id")){
weiboId = reader.nextLong();
}
}
reader.endObject();
}catch(Exception e){
e.printStackTrace();
}
return weiboId;
}
返回的Json字符串如下:
{"created_at":"Fri Aug 17 14:16:04 +0800 2012","id":3480016971496941,"mid":"3480016971496941","idstr":"3480016971496941","text":"Json ","source":"<a href=\"http://open.t.sina.com.cn\" rel=\"nofollow\">未通过审核应用</a>","favorited":false,"truncated":false,"in_reply_to_status_id":"","in_reply_to_user_id":"","in_reply_to_screen_name":"","geo":null,"user":{"id":2049309993,"idstr":"2049309993","screen_name":"A_littlemore","name":"A_littlemore","province":"11","city":"8","location":"北京 海淀区","description":"","url":"","profile_image_url":"http://tp2.sinaimg.cn/2049309993/50/5614835694/1","profile_url":"u/2049309993","domain":"","weihao":"","gender":"m","followers_count":98,"friends_count":86,"statuses_count":83,"favourites_count":0,"created_at":"Sat Oct 29 13:27:35 +0800 2011","following":false,"allow_all_act_msg":false,"geo_enabled":true,"verified":false,"verified_type":-1,"allow_all_comment":true,"avatar_large":"http://tp2.sinaimg.cn/2049309993/180/5614835694/1","verified_reason":"","follow_me":false,"online_status":0,"bi_followers_count":36,"lang":"zh-cn"},"reposts_count":0,"comments_count":0,"mlevel":0,"visible":{"type":0,"list_id":0}}...经检测在解析完created_at后再次执行hasNext()时,reader内部的name属性为null....不知道是什么原因怎么解决呢,求各位大侠帮忙啊.....
解决方案 »
- Android 编程时出现build path错误~~新手求解
- 网络收音机的数据源问题
- Android 通过通知查看详细信息
- 我的button无法显示,无报错,也对比过成功的例子,实在找不到原因
- 关于Android View方法
- 在浏览文件夹时,在ListView的Item中定义Checkbox与Item之间的冲突
- 新手求问:关于蓝牙示例程序BluetoothChat
- 怎么样将一个图片的隐藏与否作为条件?
- 求 仿大姨吗日历的demo!!! 急等
- android java.lang.reflect.InvocationTargetException
- android中导入java.awt包
- tabhost中的tab页的布局能不能单独放在一个xml文件中
if(tagName.equals("id")){
weiboId = reader.nextLong();
}改为
if(tagName.equals("id"))
{
weiboId = reader.nextLong();
return weiboId;
}