Android Question Json edit

Tom1s

Member
Licensed User
Longtime User
Hi

I got jason with http2tools
[{"CurrDate":"11-11-2014","TotalSumPerDay":"12"},{"CurrDate":"11-17-2014","TotalSumPerDay":"43"}]

I try to put these into google graphs but I cant have those currdate&totalsumperday away.

I used jsonparser and tried to get it working with this:
https://www.b4x.com/android/forum/threads/add-charts-with-google-charts-service.39197/#content

Dim parser As JSONParser
parser.Initialize(json)
Dim root As List = parser.NextArray
For Each colroot As Map In root
Dim TotalSumPerDay As String = colroot.Get("TotalSumPerDay")
Dim CurrDate As String = colroot.Get("CurrDate")
Next

I got this and no google graph. The rows part is a mess....any help?
var data = new google.visualization.DataTable({"cols":[{"type":"string","id":"","label":"CurrDate"},{"type":"number","id":"","label":"TotalSumPerDay"}],"rows":[{"c":[{"v":{"CurrDate":"11-11-2014","TotalSumPerDay":"12"}},{"v":{"CurrDate":"11-17-2014","TotalSumPerDay":"43"}}]}]});

Thanks.
 

DonManfred

Expert
Licensed User
Longtime User
In the tutorials from that link i cannot see anything what needs a json as parameters...
Which of the examples (pie, bar, line) you want to fill with the json you got from httputils?
 
Upvote 0

Tom1s

Member
Licensed User
Longtime User
I got that json from a website and i cannot change it. Thats why i try to remove the text from the json. Or i could perhaps replace Currdate&totalsumperday with "v" (as value in google string) ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
got that json from a website and i cannot change it.
you dont need to!
Just get this json and parse it (you already did that)... Then use the values like you need them to use in the pie chart example (that´s the part you are missing in your code)....
 
Last edited:
Upvote 0

Tom1s

Member
Licensed User
Longtime User
Thanks I got it working..I had problem in google charts code as well.
Still learning this but getting there slowly....
 
Upvote 0

Tom1s

Member
Licensed User
Longtime User
Another question:
I am not sure but perhaps it worked once but... how i can change APIKey and ID from srv string before it downloads.
Now log(apikey &ID) shows right input texts but log(srv) it keeps unchange

Sub Globals
Dim Job1 As HttpJob
Dim srv As String
Private APIKey As EditText
Private ID As EditText
srv = "http://....Api.ashx?method=ID&apikey=APIKey"

sub connect
Job1.Initialize("Job1", Me)
Job1.Download(srv)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
1. use code-tags when posting code!!
2. move
B4X:
Dim Job1 As HttpJob
from Globals to connect
B4X:
sub connect
Dim Job1 As HttpJob
Job1.Initialize("Job1", Me)
Job1.Download(srv)

3.
how i can change APIKey and ID from srv string before it downloads
Build srv string new in sub connect...

The point is that you actually use ONE instance of httpjob. You should generate a new instance for each job you want to start.

DIMming the job in Globals is a totally NO GO except you want to call it just ONCE!
 
Upvote 0

Tom1s

Member
Licensed User
Longtime User
Ok Thanks How do i do that Build srv string new? I am still learning...

B4X:
Sub connect
Dim srvnew As String
srvnew = ???

when I have these text places?:
B4X:
Sub ID_TextChanged (Old As String, New As String)

End Sub
Sub APIKey_TextChanged (Old As String, New As String)

End Sub
 
Last edited:
Upvote 0

Tom1s

Member
Licensed User
Longtime User
I dont know what i do wrong but still cant get it....

B4X:
SUB GLOBAL
Dim srv As String = "http://...pi.ashx?method=I&apikey=A"

SUB CONNECT
Dim A As String = APIKey.Text
Dim I As String = ID.Text

Dim srvnew As String = srv
 
Last edited:
Upvote 0

Tom1s

Member
Licensed User
Longtime User
I have red those but need check again..feel stupid but didnt find string replace... I will check again. Thank you!
 
Upvote 0

Tom1s

Member
Licensed User
Longtime User
I just tried and tried to put variables in the http: string like $apikey$ etc
Is it so that it is not even possible?

Now I came up with this solution:

B4X:
Dim srv As String = "http://........./Api.ashx?"
Dim srvnew As String = srv & "method=" & IDtxt & "&apikey=" & APIKeytxt
 
Upvote 0
Top