在asp.net中用户响应之后解析foursquare json响应

时间:2014-02-13 15:33:59

标签: c# json.net foursquare sharpsquare

我的客户希望我从传递lat long和查询短语的foursquare查询中返回一个普通的旧分隔文件或字符串。他们希望以网络形式和asp.net/vb.net。我不知道为什么我只是兑现支票。我有json响应回来,我可以写到表单上的标签,但我无法解析Foursquare json响应。我在表单上有两个文本框。一个用于latlong,一个用于查询短语。在按钮上单击我验证并调用以下代码。

Dim url As String = "https://api.foursquare.com/v2/venues/search?client_id="
        url += txtClient_ID.Text
        url += "&client_secret="
        url += txtClient_Secret.Text
        url += "&v=20140212&ll="
        url += txtLatLong.Text
        url += "&query="
        url += txtQuery.Text
        url += "&radius="
        url += txtRadius.Text
        url += "&intent=browse"

    Dim request As HttpWebRequest
    request = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)
    request.Method = "GET"
    Dim response As WebResponse = request.GetResponse()
    Dim reader As New StreamReader(response.GetResponseStream())
    Dim jsonResponse As String = reader.ReadToEnd()`

工作得非常好并返回原始json,然后我可以写入表单等。我的问题是将其变为人类可读的格式。 我已经导入了newtonsoft和sharpsquare库,并在VS中为他们的类获得了intellitype,但我似乎无法将json反序列化。在这一点上,我不在乎它是在gridview或xml还是某种制表符分隔的文本中。我试过了

 Dim root As Object = JObject.Parse(jsonResponse)

    Dim venues As JArray = root("response")("venues")
    Dim firstVenue As JObject = venues(0)

    Dim whatever As New SharpSquare(txtClient_ID.Text, txtClient_Secret.Text)
    lblParsed.Text = whatever.SearchVenues(venues)

但是得到“类型newtonsoft.json.linq.array的值无法转换为system.collection.generic.dictionary(字符串,字符串)”Sharpsquare是否与我之前的调用进行了相同的webrequest,或者我只是错过了在这些dang嵌套阵列上划船?我在sharpsquare上找不到任何文档,唯一的代码示例是

Imports FourSquare.SharpSquare.Core
Imports FourSquare.SharpSquare.Entities
Dim clientId As String = "my client id"
    Dim clientSecret As String = "my client secret"
    Dim redirectUri As String = "REDIRECT_URI"
    Dim sharpSquare As New SharpSquare(clientId, clientSecret)

哪个没有错误,但我现在该怎么做才能获得实际结果?我已经在这几天了,任何帮助都会受到赞赏。

0 个答案:

没有答案