我终于使用 javascriptserializer 来反序列化 json 内容。现在我在字典中有对象,并且想访问内容以获取键值。我只想获取某些字段的值。
{
"data": [
{
"id": "56381779049_10150352298839050",
"from": {
"name": "Paulina Soto",
"id": "1619854594"
},
"to": {
"data": [
{
"name": "Pepsi",
"category": "Food/beverages",
"id": "56381779049"
}
]
},
"message": "La coca es mejor que la pepsi :D.",
"type": "status",
"created_time": "2011-08-11T20:43:18+0000",
"updated_time": "2011-08-11T20:43:18+0000",
"comments": {
"count": 0
}
},
{
"id": "56381779049_10150352296084050",
"from": {
"name": "William Scott Jennings",
"id": "1125852789"
},
"to": {
"data": [
{
"name": "Pepsi",
"category": "Food/beverages",
"id": "56381779049"
}
]
},
"message": "Don't buy the new Pepsi can coming out with pictures of the Empire State building and The Pledge of Allegiance on them. Pepsi left out two little words on the pledge, \"Under God.\" Pepsi said they didn't want to offend anyone. So if we don't buy them they won't be offended when they don't receive our money that has the words \"In God We Trust\" on it. How fast can you re post this? It is offensive to leave out Under God\r\nDon't buy the new Pepsi can coming out with pictures of the Empire State building and The Pledge of Allegiance on them. Pepsi left out two little words on the pledge, \"Under God.\" Pepsi said they didn't want to offend anyone. So if we don't buy them they won't be offended when they don't receive our money that has the words \"In God We Trust\" on it. How fast can you re post this? It is offensive to leave out Under God\r\n",
"type": "status",
"created_time": "2011-08-11T20:39:59+0000",
"updated_time": "2011-08-11T20:39:59+0000",
"comments": {
"count": 0
}
},
{
"id": "56381779049_10150352295939050",
"from": {
"name": "William Scott Jennings",
"id": "1125852789"
},
"to": {
"data": [
{
"name": "Pepsi",
"category": "Food/beverages",
"id": "56381779049"
}
]
},
"message": "Don't buy the new Pepsi can coming out with pictures of the Empire State building and The Pledge of Allegiance on them. Pepsi left out two little words on the pledge, \"Under God.\" Pepsi said they didn't want to offend anyone. So if we don't buy them they won't be offended when they don't receive our money that has the words \"In
反序列化代码;
dim dserial as new javascriptSerializer()
Dim ddict as Dictionary(of String, Object) = dserial.Deserialize(Of Dictionary(Of string, object))(jsonData)
我现在如何获取 id、from、name、id、to ...等字段?请有任何想法。
{更新}
感谢回复。当我在等待时,我尝试了其他方法,发现如果我只能获得一些关于此的注释或示例,似乎是一种更简单的方法。
dim results as list(of JToken) = jobj.("data").Children().ToList()
for each item as Jtoken in results
uid = item("id")
if item.type = JTokenType.Object then
author = item.SelectToken("from.name")
authorId = item.SelectToken("from.id")
end if
msg = item("message")
next
好的,这似乎更容易,但我不知道如何遍历令牌对象。未读取消息字段,因为我猜该类型仍然是 Object ,我想知道如何通过这个单独的 JToken 并获取字段。