【发布时间】:2014-02-05 06:42:12
【问题描述】:
我使用 gson 库来解析 json 响应。它运作良好。现在我遇到了问题。
我收到以下来自网络服务的响应。 json键值不是静态的,会动态变化的。
如何编写解析器类来解析以下响应。
格式化的 JSON:
{
"meta": {
"code": 201,
"dataPropertyName": "activity",
"currentTime": "2014-02-05 06:15:04",
"listedCount": "2"
},
"activity": [
{
"comments": [
{
"raja": {
"type": "Liked",
"userPhoto": "663.png",
"userId": "74",
"userName": {
"1_0": "longjump"
},
"postOwner": "you",
"postDetails": {
"471": {
"postImage": "972.png",
"postId": "471",
"postType": "1"
}
},
"dateTime": "2014-02-05 05:24:56",
"sameOwner": "1"
}
}
]
},
{
"follow": [
{
"you": {
"type": "follow",
"followByUserName": {
"0_0": "olivepop",
"1_0": "yadidroy",
"2_0": "chitra"
},
"followUserName": "you",
"followByUserPhoto": "242.png",
"followUserPhoto": "953.png",
"dateTime": "2014-01-09 06:50:42"
}
}
]
}
],
"notifications": [
"Activities has been retrieved successfully"
]
}
【问题讨论】:
-
你有一个特定的动态键
-
哪些字段不是静态的...?您提供的示例 json str 中的所有内容都相同。
-
在那个响应中 raja,471,you,1_0,2_0,3_0, 是动态键值