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 ...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
これははるかに簡単に思えますが、トークン オブジェクトをトラバースする方法がわかりません。タイプはまだオブジェクトであるため、メッセージフィールドは読み取られません。この個々の JToken をどのように調べてフィールドを取得できるか疑問に思っていました。