在解析VB.NET谷歌JSON响应 [英] Parse Google JSON response in VB.NET
问题描述
我试图解析JSON响应形式谷歌。这是我目前有:
I'm trying to parse the JSON response form google. This is what I currently have:
Dim x As New System.Web.Script.Serialization.JavaScriptSerializer
Dim gJson As String = ""
Dim wClient As New WebClient
wClient.Proxy = System.Net.HttpWebRequest.DefaultWebProxy
gJson = wClient.DownloadString("https://www.googleapis.com/...alt=json")
Dim results As gResponseClass = x.Deserialize(Of gResponseClass)(gJson)
gResponseClass
,如下所示:引擎收录
我不断收到以下异常抛出:
I keep getting the following exception thrown:
无效的对象传入,成员名字的预期。 (6678).... *这里的JSON响应* ...
有没有我可以实现任何公然的问题或解决方案?
Is there any blatant problems or solutions I could implement?
修改
从谷歌JSON响应: JSON响应
The JSON response from google: JSON Response
修改
只是为了延续用途:误差修改确实是套管的,
Facebook上的页映射
节点中页面。我已经使出调用清理功能如下:
Just for continuation purposes: the erros is cased indeed by the "":
inside the pagemap
node on facebook pages. I have resorted to calling a cleanup function as follows:
json = json.Replace(""""":", """page_id"":")
Return json
如果任何人有一个更好的办法,请让我知道!
If anyone has a better way, please let me know!
再次感谢。
推荐答案
看起来这是它的时遇到问题的JSON的位:
It looks like this is the bit of the JSON it's having trouble with:
"": [
{
"page_id": "66721388277"
}
],
我不是一个JSON的专家,但我可以看到为什么它可能是由感到惊讶。正如我所提到的,它可以通过 Json.NET (至少为<$ C $解析C> JObject ),所以你可能要使用到尝试吧。
I'm not a JSON expert, but I can see why it might be surprised by that. As I mentioned, it can be parsed by Json.NET (at least as a JObject
) so you might want to try using that instead.
原来的答复,仍然适用
的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.deserializeobject.aspx\"相对=nofollow> DeserializeObject
法规定:
这反序列化方法不尝试将对象图的根转换为特定类型,与Deserialize方法。
This deserialization method does not try to cast the root of the object graph to a specific type, as with the Deserialize method.
所以,我会感到惊讶,如果它成功地转换为 gResponseClass
反正。您是否尝试过使用 反序列化
方法呢?
So I'd be surprised if it managed to cast to gResponseClass
anyway. Have you tried using the Deserialize
method instead?
(我会预期编译时错误,说实话 - 你有选择的严格和明确的选项?)
(I'd have expected a compile-time error to be honest - do you have option strict and option explicit on?)
这可能不是你面临的问题,但它是我想看看反正第一件事情:)的JSON解析罚款JSON.NET。
That may well not be the problem you're facing, but it's the first thing I'd look at anyway :) The JSON parses fine with JSON.NET.
这篇关于在解析VB.NET谷歌JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!