john hill
asked on
json string
Hello Experts
I am getting a json response from a URL which I am trying parse it and capture code to store in the DB
Its returning the string ok but I am unable to remove the quoted strings to save the code in the DB
Dim jResults As Object = JObject.Parse(Json)
Dim jsonResulttodict = JsonConvert.DeserializeObj ect(Of Dictionary(Of String, Object))(Json)
Dim firstItem = jsonResulttodict.Item("err or")
Dim seconditem = jsonResulttodict.Item("suc cess")
Dim thirditem = jsonResulttodict.Item("cod es")
example string:
'{"error":"","success":"1 code generated successfully","codes":["QT ESTA2HLT"] }
I am getting the code as [{ "QTESTA2HLT" }]
Al I want is to read as QTESTA2HLT
please advise
thanks
I am getting a json response from a URL which I am trying parse it and capture code to store in the DB
Its returning the string ok but I am unable to remove the quoted strings to save the code in the DB
Dim jResults As Object = JObject.Parse(Json)
Dim jsonResulttodict = JsonConvert.DeserializeObj
Dim firstItem = jsonResulttodict.Item("err
Dim seconditem = jsonResulttodict.Item("suc
Dim thirditem = jsonResulttodict.Item("cod
example string:
'{"error":"","success":"1 code generated successfully","codes":["QT
I am getting the code as [{ "QTESTA2HLT" }]
Al I want is to read as QTESTA2HLT
please advise
thanks
maybe you should use
or
Dim thirditem = jsonResulttodict.Item("codes")(0)
or
thirditem = thirditem.replace("[{ ""","").replace(""" }]","")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I agree with Fernando, the issue is that codes is an array. Please accept above for your case but for others who were looking to remove quotes in text value, the escape character is a slash; therefore, it would be .replaceAll("\"", "");
@Kevin
this is vb.net, so double " in string is a single "
and no need to convert to string!
if you look at authors code, he is getting the correct value with
so, as I mentioned in my post above, ID: 42305599, both should work:
or, string replace
the escape character is a slash; therefore, it would be .replaceAll("\"", "");
this is vb.net, so double " in string is a single "
and no need to convert to string!
if you look at authors code, he is getting the correct value with
Dim thirditem = jsonResulttodict.Item("codes")
so, as I mentioned in my post above, ID: 42305599, both should work:
Dim thirditem = jsonResulttodict.Item("codes")(0)
or, string replace
thirditem = thirditem.replace("[{ ""","").replace(""" }]","")
Ah, too sleepy. I thought it was JavaScript. Saw the JSON and didn't look at the question zones. Point still stands that the issue is the array versus bad quotes in the string. The solution is to use the index of first element versus parsing the string representation of the array, so you are correct that both your second code above and Fernando's post should work. I vote YES.
ASKER
thank you so much for your input
Not a problem John, glad to help.
Open in new window
to get rid of "s