格式错误的Json语法异常android

时间:2014-03-11 06:13:35

标签: android json

这是服务器响应

[{bookmark={}, comments=[], createdOn={date=7.0, day=5.0, hours=14.0, minutes=0.0, month=2.0, nanos=0.0, seconds=0.0, time=1.3942008E12, timezoneOffset=0.0, year=114.0}, event={}, fileContentType=, fileName=, fileSize=0.0, fileUrl=, hasFile=0.0, image={}, isCommented=0.0, isLike=false, isOnlyMe=false, isPolled=false, isRsvp=false, isSpamed=0.0, ismoderated=0.0, keywords=[], meetingId=0.0, modifiedOn={date=7.0, day=5.0, hours=14.0, minutes=0.0, month=2.0, nanos=0.0, seconds=0.0, time=1.3942008E12, timezoneOffset=0.0, year=114.0}, originalId=0.0, parentId=0.0, parentPost=, parentPostCreatedOn={date=7.0, day=5.0, hours=14.0, minutes=0.0, month=2.0, nanos=0.0, seconds=0.0, time=1.3942008E12, timezoneOffset=0.0, year=114.0}, parentPostUserEmailAddress=, parentPostUserId=0.0, parentPostUserName=, pollOptions=[], post=Hi All,~|~~|~We have provided MMv3 User Guide on below location~|~URL: http://mmv3.qlc.co.in/ms/MMv3_Help/MailServe_v3.00.html~|~~|~Please provide us your suggestions and feedback., postId=39629.0, postShareWithId=[], postType=1.0, postUserId=100021.0, postVisibility=0.0, selectedPollOption=0.0, selectedRsvp=0.0, sourceId=449.0, sourceName=All QLC, sourceType=2.0, tag=[], tagId=[], tags= , user={address=, blogSiteUrl=, certificates=, college=, connectionCount=0.0, created={}, description=, emailAddress=ashwini.nimbargi@qlc.in, facebookProfile=, firstName=Ashwini, groupCount=0.0, highestDegree=, id=0.0, lastName=Nimbargi, linkedInProfile=, locationId=0.0, mobileNumber=0.0, modified={}, nickName=Ashwini Nimbargi, otherPhone=0.0, password=, pinCode=0.0, previousEmployer=, twitterProfile=, type=0.0, university=, userCommunityId=0.0, userId=100021.0, userPreference={}, website=}, userFile={}, video={}, wallPostSummary={commentCount=0.0, likeCount=4.0, modifiedOn={date=7.0, day=5.0, hours=14.0, minutes=0.0, month=2.0, nanos=0.0, seconds=0.0, time=1.3942008E12, timezoneOffset=0.0, year=114.0}, postId=39629.0, spamCount=0.0, wallPostSummaryId=29777.0}}, {bookmark={}, comments=[], createdOn={date=7.0, day=5.0, hours=12.0, minutes=44.0, month=2.0, nanos=0.0, seconds=31.0, time=1.394196271E12, timezoneOffset=0.0, year=114.0}, event={}, fileContentType=, fileName=, fileSize=0.0, fileUrl=, hasFile=0.0, image={}, isCommented=0.0, isLike=false, isOnlyMe=false, isPolled=false, isRsvp=false, isSpamed=0.0, ismoderated=0.0, keywords=[], meetingId=0.0, modifiedOn={date=7.0, day=5.0, hours=12.0, minutes=44.0, month=2.0, nanos=0.0, seconds=31.0, time=1.394196271E12, timezoneOffset=0.0, year=114.0}, originalId=0.0, parentId=0.0, parentPost=, parentPostCreatedOn={date=7.0, day=5.0, hours=12.0, minutes=44.0, month=2.0, nanos=0.0, seconds=31.0, time=1.394196271E12, timezoneOffset=0.0, year=114.0}, parentPostUserEmailAddress=, parentPostUserId=0.0, parentPostUserName=, pollOptions=[], post=t, postId=39627.0, postShareWithId=[], postType=1.0, postUserId=100220.0, postVisibility=0.0, selectedPollOption=0.0, selectedRsvp=0.0, sourceId=449.0, sourceName=All QLC, sourceType=2.0, tag=[], tagId=[], tags= , user={address=, blogSiteUrl=, certificates=, college=, connectionCount=0.0, created={}, description=, emailAddress=pankaj.sharma@qlc.in, facebookProfile=, firstName=Pankaj, groupCount=0.0, highestDegree=, id=0.0, lastName=Sharma, linkedInProfile=, locationId=0.0, mobileNumber=0.0, modified={}, nickName=Pankaj Sharma, otherPhone=0.0, password=, pinCode=0.0, previousEmployer=, twitterProfile=, type=0.0, university=, userCommunityId=0.0, userId=100220.0, userPreference={}, website=}, userFile={}, video={}, wallPostSummary={commentCount=0.0, likeCount=0.0, modifiedOn={date=7.0, day=5.0, hours=12.0, minutes=44.0, month=2.0, nanos=0.0, seconds=31.0, time=1.394196271E12, timezoneOffset=0.0, year=114.0}, postId=39627.0, spamCount=0.0, wallPostSummaryId=29775.0}}]

当我尝试解析它时,我得到了异常

com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unexpected value at line 1 column 198

这是我的java代码

Log.e(TAG, fromJson.getResponse().getResult().toString());

            WallPost[] fromJson2 = gson.fromJson(fromJson.getResponse().getResult().toString(), WallPost[].class);
//
            Log.e(TAG, "length: "+fromJson2.length);

1 个答案:

答案 0 :(得分:1)

试试这个

Gson gson = new Gson();
Type collectionType = new TypeToken<Collection<WallPost>>(){}.getType();
Collection<WallPost> collObj = gson.fromJson(gson.toJson( obj.Data), collectionType);
List<WallPost> lst = new ArrayList<WallPost>(collObj);

参考: https://sites.google.com/site/gson/gson-user-guide#TOC-Array-Examples