0

Generally i parse a XML String as followed :

The XML String i recieve

<Status>string</Status>
        <RedirectURL>string</RedirectURL>

The way i parse it

Dim sReason As String = "Unknown"

        Try
            xml.LoadXml(sResult)
            If xml.SelectSimpleNode("Status").InnerText = "PURCHASED" Then
                app.Outcome.RedirectURL = xml.SelectSimpleNode("RedirectUrl").InnerText
                AcceptLead()
                Return True
            End If

Now i need to parse a string that is not delivered in XML , but is delivered to me as followed

{"RedirectUrl":"www.test.com","Commission":5.0000,"Status":"accepted"}

How do i do this ?

The values are just in a string, someone told me i can pull the data from the string and then allocate it where i need it, but i do not know how.

Trifactor
  • 59
  • 9
  • possible duplicate of [Parsing in Json not in XML . VB.Net](http://stackoverflow.com/questions/25808129/parsing-in-json-not-in-xml-vb-net) – har07 Sep 12 '14 at 14:35
  • 1
    That's JSON (javascript object notation). There are a number of JSON parsers available for .Net, several of which are on Nuget. – Joel Coehoorn Sep 12 '14 at 14:41
  • 1
    If you don't want to use one of the JSON parsers, I'd split the string on the commas to find the key/value pairs, and then again on the colons to retrieve the keys and the values. – Seth Sep 12 '14 at 14:44
  • possible duplicate of [How to parse json in C#?](http://stackoverflow.com/questions/6620165/how-to-parse-json-in-c) – Bjørn-Roger Kringsjå Sep 17 '14 at 16:50

1 Answers1

0
sResult = sResult.Replace("""", String.Empty)
            If sResult.Contains("Status:accepted") Then
                Dim parts = sResult.Replace("{", String.Empty).Replace("}", String.Empty).Split(",")
                For i As Int16 = 0 To parts.Length - 1
                    If parts(i).StartsWith("RedirectUrl") Then
                        app.Outcome.RedirectURL = parts(i).Substring(12)
                    End If
                    If parts(i).StartsWith("Commission") Then
                        lendertier.LenderComm = CDec(parts(i).Substring(11))
                    End If
                    If parts(i).StartsWith("ApplicationRef") Then
                        app.Outcome.LenderReference = parts(i).Substring(15)
                    End If
                Next
                AcceptLead()
                Return True
            End If
            If sResult.Contains("Reason:Duplicate") Then
                sReason = "Duplicate"
            ElseIf sResult.Contains("{Error:invalid credentials") Then
                sReason = "Error: Invalid credentials"
            ElseIf sResult.Contains("ValidationErrors:") Then
                sReason = "Invalid call:" + sResult.Replace("ValidationErrors:", String.Empty).Replace(",Status:rejected", String.Empty)
            Else
                sReason = "Rejected"
            End If
            DeclineLead(sReason)
            Return False
Trifactor
  • 59
  • 9