反序列化Facebook API响应

时间:2015-02-19 07:37:47

标签: json facebook api serialization response

我创建了一个vb-programm,它发送一个Facebook-API请求并将其反序列化为我使用它创建的对象:

Dim PostList As JsonPostList = Deserializer.Deserialize(Of JsonPostList)(LoadJsonFromUrl("https://graph.facebook.com/" & Params("Userid") & "/feed?fields=id,message,type,actions,picture,link,created_time&limit=30&access_token=" + ACCESSTOKEN))
直到昨天,这个工作很有效。今天早上,上面的代码返回“Type'System.String'不支持反序列化数组。”

Facebook响应中的某些内容发生了变化吗?

LoadJsonFromUrl只是将Response转换为String:

Private Function LoadJsonFromUrl(Url As String) As String

    Dim Text As String = ""

    ' --- Request --- '
    Dim Uri As Uri = New Uri(Url)
    Dim Request As HttpWebRequest = CType(WebRequest.Create(Uri), HttpWebRequest)
    Request.Method = WebRequestMethods.Http.Get
    Request.Timeout = 30000

    ' --- Response --- '
    Dim Response As HttpWebResponse = CType(Request.GetResponse(), HttpWebResponse)
    Dim Encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding(Response.CharacterSet)

    ' --- Stream --- '
    Using Stream As IO.Stream = Response.GetResponseStream()

        Using Reader As StreamReader = New StreamReader(Stream, Encoding)
            Text = String.Copy(Reader.ReadToEnd())
        End Using

    End Using

    Response.Close()

    Logger.Write(Text, Logger.MessageType.Info)
    ' Return
    Return Text

End Function

我的课程:

Public Class JsonPostList

    Public data As List(Of JsonPostData)
    Public pageing As JsonPaging

End Class

Public Class JsonPostData

    Public id As String
    Public message As String
    Public type As String
    Public actions As String
    Public picture As String
    Public link As String
    Public created_time As String

End Class

Public Class JsonPaging

    Public [next] As String
    Public [previous] As String

End Class

1 个答案:

答案 0 :(得分:0)

好的,显然是在Facebook api"行动"进入一个数组。我排除了行动,现在工作正常。