Я наконец-то заставил это работать, используя 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, name, id, to ... etc?
Любые идеи, пожалуйста.
{обновлено}
оцените ответ. Пока я ждал, я попробовал что-то еще и нашел способ, который кажется более простым, если я смогу получить только некоторые заметки или примеры по этому поводу.
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 и захватить поля.