I have this string:
1=True&2=150+minutes&3=True&4=True&5=Continuing+to+smoke
How can I get it into an array or object like this:
[1] => True
[2] => "150 minutes"
etc?
I have tried this:
<HttpPost()>
Function GetQuizScore(ByVal data As String) As JsonResult
'Debug.Print(data)
Dim jss = New JavaScriptSerializer
Dim dict = jss.Deserialize(Of List(Of String))(data)
Debug.Print(String.Join(", ", dict))
Return Json(data)
End Function
But, it gives me an error that says:
Invalid JSON primitive: True&2=150+minutes&3=True&4=True&5=Continuing+to+smoke.
Thanks for your help.
The string you have is a QueryString, not a JSON string. Thus, you can use
to convert it into a NameValueCollection.
Example:
Dim s = "1=True&2=150+minutes&3=True&4=True&5=Continuing+to+smoke"
Dim parsed = HttpUtility.ParseQueryString(s)
For Each key In parsed
Console.WriteLine(key & ": " & parsed(key))
Next
Output:
1: True
2: 150 minutes
3: True
4: True
5: Continuing to smoke
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With