locked
Help required parsing a JSON RRS feed

  • Question

  • User-910361580 posted

    Hi

    I am stuck with this for last 2 days. Please help. Here is the JSON structure that needs to be parsed and stored in db.

    {
    "request": {
    "Target": "Affiliate_Offer",
    "_ga": "GA1.2.378233870.1449144511",
    "_gat": "1"
    },
    "response": {
    "status": 1,
    "httpStatus": 200,
    "data": {
    "page": 1,
    "current": 0,
    "count": 184,
    "pageCount": 92,
    "data": [
    {
    "Offer": {
    "id": "1578",
    "name": "1mg.com CPS - India",
    "dne_third_party_list": false
    }
    },
    {
    "Offer": {
    "id": "2359",
    "name": "777.com CPL – GCC",
    "dne_third_party_list": false
    }
    }
    ]
    },
    "errors": [],
    "errorMessage": null
    }

    The classes generated by visual studio are:

    Public Class Rootobject
    Public Property request As Request
    Public Property response As Response
    End Class

    Public Class Request
    Public Property Target As String
    Public Property _ga As String
    Public Property _gat As String
    End Class

    Public Class Response
    Public Property status As Integer
    Public Property httpStatus As Integer
    Public Property data As Data
    Public Property errors() As Object
    Public Property errorMessage As Object
    End Class

    Public Class Data
    Public Property page As Integer
    Public Property current As Integer
    Public Property count As Integer
    Public Property pageCount As Integer
    Public Property data() As Datum
    End Class

    Public Class Datum
    Public Property Offer As Offer
    End Class

    Public Class Offer
    Public Property id As String
    Public Property name As String
    Public Property dne_third_party_list As Boolean
    End Class

    Dim client As New WebClient()
    Dim jsonstring As String = client.DownloadString("https://api.someurl.com")

    Dim jsonObject As Rootobject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Rootobject)(jsonstring)

    I have to now parse through the jsonobject and get to the offers and store each offer in database.

    All help is appreciated.

    Thanks a lot

    Tuesday, December 8, 2015 1:29 AM

Answers

  • User-2057865890 posted

    Hi,schadha

    Dim jsonObject As Rootobject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Rootobject)(jsonstring)

    I have to now parse through the jsonobject and get to the offers and store each offer in database.

    You have deserialized jsonstring as Rootobject.

    You can access offers by jsonObject.Response....Offer.

    About "store each offer in database",you could refer to the following.

    How to: Insert New Records into a Database

    Best regards,

    Chris Zhao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 10, 2015 5:32 AM

All replies

  • User-2057865890 posted

    Hi,schadha

    Dim jsonObject As Rootobject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Rootobject)(jsonstring)

    I have to now parse through the jsonobject and get to the offers and store each offer in database.

    You have deserialized jsonstring as Rootobject.

    You can access offers by jsonObject.Response....Offer.

    About "store each offer in database",you could refer to the following.

    How to: Insert New Records into a Database

    Best regards,

    Chris Zhao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 10, 2015 5:32 AM
  • User-910361580 posted

    Thanks a lot Chris.

    Thursday, December 17, 2015 6:48 PM