organizing and removing unwanted numbers from datagridview
Hello guys,
I have this code here that updates my gridviewdata with a json file every time i click a button.
Code:
DataGridView2.Rows.Clear()
Dim uri As Uri = New Uri("https://api.import.io/store/connector/06a2a24f-6678-407e-8ad0-c7cbe24cf33c/_query?input=webpage/url:http%3A%2F%2Ffxowebtools.saxobank.com%2Fretail.html&&_apikey=d4c36ddd8f8d4a629bdf06e47993809233ac34a0ee817f4af327f7e016e1cb0921ba78b0da4d9be881051cbf3cf672f1425214d8e687e33559e24fdd17bc5a606e8ce1eac3d6e064593e3fcc34d23344")
Dim wc1 As System.Net.WebClient = New System.Net.WebClient()
Dim VCItem As String = wc1.DownloadString(uri)
Dim o As JObject = JObject.Parse(VCItem)
Dim results As List(Of JToken) = o.Children().ToList
Try
For Each item As JProperty In results
item.CreateReader()
If item.Value.Type = JTokenType.Array Then
For Each subitem As JObject In item.Values
DataGridView2.Rows.Add(subitem("leftlabelcells_value"), (subitem("hideextra_number")), (subitem("rightpositioncells_number")))
Next
End If
Next
Catch ex As Exception
End Try
this is the data i get in my gridviewdata
there is some unwanted data in my gridview in the second and third coulmn, i need them to be like this :
in other words, i need to take off all the brackets and all the digits after the first comma or the first decimal point.
any help would be greatly appreciated !
Basically for the last two columns I replace all spaces, open brackets, and close brackets with an empty String and then I split the value by a comma and get the first item from the split.
Edit - I also convert the values returned from the process described to an Integer which will round all values down and remove the decimal place.
Basically for the last two columns I replace all spaces, open brackets, and close brackets with an empty String and then I split the value by a comma and get the first item from the split.
Edit - I also convert the values returned from the process described to an Integer which will round all values down and remove the decimal place.
thank you for your input dday, but unfortunetly i get a an error ; Too many arguments to 'Public Overloads Sub Replace(value As JToken)'.
Last edited by hyperbell; Mar 25th, 2016 at 12:54 PM.
Dim uri As Uri = New Uri("https://api.import.io/store/connector/06a2a24f-6678-407e-8ad0-c7cbe24cf33c/_query?input=webpage/url:http%3A%2F%2Ffxowebtools.saxobank.com%2Fretail.html&&_apikey=d4c36ddd8f8d4a629bdf06e47993809233ac34a0ee817f4af327f7e016e1cb0921ba78b0da4d9be881051cbf3cf672f1425214d8e687e33559e24fdd17bc5a606e8ce1eac3d6e064593e3fcc34d23344")
Dim wc1 As System.Net.WebClient = New System.Net.WebClient()
Dim VCItem As String = wc1.DownloadString(uri)
Re: organizing and removing unwanted numbers from datagridview
Originally Posted by dday9
Ok, I had thought that the value was a String value. What does the JToken class look like, is there a Text property?
I doubt it... it looks based on its use that JToken is an enumerated type... it's checking if the type of the value of the item is an array or not...
I think we'd need to know a bit more about what each item is (beyond being a JProperty) and what it's .Value is like...
-tg
Last edited by techgnome; Mar 25th, 2016 at 02:36 PM.
Re: organizing and removing unwanted numbers from datagridview
Originally Posted by dday9
Try changing GetType(String) to Of String.
thank you for trying, i am stuck with this code for the past 2 days.
the new change does not show anymore errors but in runtime when its fetching data, it stops and get a new error :
An unhandled exception of type 'System.InvalidCastException' occurred in Newtonsoft.Json.dll
Additional information: Cannot cast Newtonsoft.Json.Linq.JArray to Newtonsoft.Json.Linq.JToken.