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.

4
  • possible duplicate of Parsing in Json not in XML . VB.Net Commented Sep 12, 2014 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. Commented Sep 12, 2014 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. Commented Sep 12, 2014 at 14:44
  • possible duplicate of How to parse json in C#? Commented Sep 17, 2014 at 16:50

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.