TrisectDevelopment Active Member Licensed User Longtime User May 12, 2014 #1 I'm having a little trouble with httputils2 and json. I have two URLs and one of them Work in my program but the other does not. Funny part is if I enter the two URLs in my browser they both return an json file. But in my code I get an error on one of them. URL1: (this one is giving me an error in B4A) http://www.broens-byfest.dk/?json=get_category_posts&category_slug=Nyheder URL2: (this one works okay. I know its not the same result) http://www.broens-byfest.dk/?json=get_tag_post&tag_slug=nyheder This is my download code: Code: Copy nyhedsJob.Initialize("nyhedsJob", Me) nyhedsJob.Download2(UrlNyheder, Array As String("first key", "first value", "second key", "second value")) This is my JobDone code Code: Copy Sub JobDone(Job As HttpJob) Log("string = " & Job.GetString) If Job.Success = True Then Select Job.JobName Case "nyhedsJob" '** Det hentede JSON skal gemmes på telefonen Dim s As String Dim TextWriteNyheder As TextWriter s = Job.GetString TextWriteNyheder.Initialize(File.OpenOutput(File.DirInternal, "nyheder.json", False)) TextWriteNyheder.Write(s) TextWriteNyheder.Close '** Parse det hentede JSON data ParseJson End Select Else Log("Error: " & Job.ErrorMessage) ToastMessageShow("Error: " & Job.ErrorMessage, True) End If End Sub The ParseJson is the sub to parse the json, but in URL1 the s variable gives me a string with error. Code: Copy {"status":"error","error":"Not found."} I cant figure out what is wrong. Can any one help?
I'm having a little trouble with httputils2 and json. I have two URLs and one of them Work in my program but the other does not. Funny part is if I enter the two URLs in my browser they both return an json file. But in my code I get an error on one of them. URL1: (this one is giving me an error in B4A) http://www.broens-byfest.dk/?json=get_category_posts&category_slug=Nyheder URL2: (this one works okay. I know its not the same result) http://www.broens-byfest.dk/?json=get_tag_post&tag_slug=nyheder This is my download code: Code: Copy nyhedsJob.Initialize("nyhedsJob", Me) nyhedsJob.Download2(UrlNyheder, Array As String("first key", "first value", "second key", "second value")) This is my JobDone code Code: Copy Sub JobDone(Job As HttpJob) Log("string = " & Job.GetString) If Job.Success = True Then Select Job.JobName Case "nyhedsJob" '** Det hentede JSON skal gemmes på telefonen Dim s As String Dim TextWriteNyheder As TextWriter s = Job.GetString TextWriteNyheder.Initialize(File.OpenOutput(File.DirInternal, "nyheder.json", False)) TextWriteNyheder.Write(s) TextWriteNyheder.Close '** Parse det hentede JSON data ParseJson End Select Else Log("Error: " & Job.ErrorMessage) ToastMessageShow("Error: " & Job.ErrorMessage, True) End If End Sub The ParseJson is the sub to parse the json, but in URL1 the s variable gives me a string with error. Code: Copy {"status":"error","error":"Not found."} I cant figure out what is wrong. Can any one help?
TrisectDevelopment Active Member Licensed User Longtime User May 12, 2014 #2 I use the same URL in my iPhone App and its working fine. Its just when I try to make the App for Android I get this error with the URL. Upvote 0
I use the same URL in my iPhone App and its working fine. Its just when I try to make the App for Android I get this error with the URL.
DonManfred Expert Licensed User Longtime User May 12, 2014 #3 try Code: Copy nyhedsJob.Initialize("nyhedsJob", Me) nyhedsJob.Download2("http://www.broens-byfest.dk/", Array As String("json", "get_category_posts", "category_slug", "category_slug=Nyheder")) btw: You should give ParseJson a parameter... Code: Copy ParseJson(s) Code: Copy sub Parsejson(json as string) Dim parser As JSONParser parser.Initialize(json) Dim root As Map = parser.NextObject Dim category As Map = root.Get("category") Dim id As Int = category.Get("id") Dim title As String = category.Get("title") Dim description As String = category.Get("description") Dim post_count As Int = category.Get("post_count") Dim parent As Int = category.Get("parent") Dim slug As String = category.Get("slug") Dim count As Int = root.Get("count") Dim status As String = root.Get("status") Dim pages As Int = root.Get("pages") Dim posts As List = root.Get("posts") For Each colposts As Map In posts Dim custom_fields As Map = colposts.Get("custom_fields") Dim comment_count As Int = colposts.Get("comment_count") Dim tags As List = colposts.Get("tags") Dim status As String = colposts.Get("status") Dim excerpt As String = colposts.Get("excerpt") Dim comment_status As String = colposts.Get("comment_status") Dim type As String = colposts.Get("type") Dim date As String = colposts.Get("date") Dim url As String = colposts.Get("url") Dim modified As String = colposts.Get("modified") Dim id As Int = colposts.Get("id") Dim content As String = colposts.Get("content") Dim author As Map = colposts.Get("author") Dim id As Int = author.Get("id") Dim first_name As String = author.Get("first_name") Dim nickname As String = author.Get("nickname") Dim description As String = author.Get("description") Dim name As String = author.Get("name") Dim last_name As String = author.Get("last_name") Dim slug As String = author.Get("slug") Dim url As String = author.Get("url") Dim title As String = colposts.Get("title") Dim slug As String = colposts.Get("slug") Dim categories As List = colposts.Get("categories") For Each colcategories As Map In categories Dim id As Int = colcategories.Get("id") Dim title As String = colcategories.Get("title") Dim description As String = colcategories.Get("description") Dim post_count As Int = colcategories.Get("post_count") Dim parent As Int = colcategories.Get("parent") Dim slug As String = colcategories.Get("slug") Next Dim attachments As List = colposts.Get("attachments") Dim comments As List = colposts.Get("comments") Dim title_plain As String = colposts.Get("title_plain") Next end sub Upvote 0
try Code: Copy nyhedsJob.Initialize("nyhedsJob", Me) nyhedsJob.Download2("http://www.broens-byfest.dk/", Array As String("json", "get_category_posts", "category_slug", "category_slug=Nyheder")) btw: You should give ParseJson a parameter... Code: Copy ParseJson(s) Code: Copy sub Parsejson(json as string) Dim parser As JSONParser parser.Initialize(json) Dim root As Map = parser.NextObject Dim category As Map = root.Get("category") Dim id As Int = category.Get("id") Dim title As String = category.Get("title") Dim description As String = category.Get("description") Dim post_count As Int = category.Get("post_count") Dim parent As Int = category.Get("parent") Dim slug As String = category.Get("slug") Dim count As Int = root.Get("count") Dim status As String = root.Get("status") Dim pages As Int = root.Get("pages") Dim posts As List = root.Get("posts") For Each colposts As Map In posts Dim custom_fields As Map = colposts.Get("custom_fields") Dim comment_count As Int = colposts.Get("comment_count") Dim tags As List = colposts.Get("tags") Dim status As String = colposts.Get("status") Dim excerpt As String = colposts.Get("excerpt") Dim comment_status As String = colposts.Get("comment_status") Dim type As String = colposts.Get("type") Dim date As String = colposts.Get("date") Dim url As String = colposts.Get("url") Dim modified As String = colposts.Get("modified") Dim id As Int = colposts.Get("id") Dim content As String = colposts.Get("content") Dim author As Map = colposts.Get("author") Dim id As Int = author.Get("id") Dim first_name As String = author.Get("first_name") Dim nickname As String = author.Get("nickname") Dim description As String = author.Get("description") Dim name As String = author.Get("name") Dim last_name As String = author.Get("last_name") Dim slug As String = author.Get("slug") Dim url As String = author.Get("url") Dim title As String = colposts.Get("title") Dim slug As String = colposts.Get("slug") Dim categories As List = colposts.Get("categories") For Each colcategories As Map In categories Dim id As Int = colcategories.Get("id") Dim title As String = colcategories.Get("title") Dim description As String = colcategories.Get("description") Dim post_count As Int = colcategories.Get("post_count") Dim parent As Int = colcategories.Get("parent") Dim slug As String = colcategories.Get("slug") Next Dim attachments As List = colposts.Get("attachments") Dim comments As List = colposts.Get("comments") Dim title_plain As String = colposts.Get("title_plain") Next end sub
TrisectDevelopment Active Member Licensed User Longtime User May 12, 2014 #4 Thanks for your answer but I still get the same error. Upvote 0
DonManfred Expert Licensed User Longtime User May 12, 2014 #5 No, it works for me Attachments TrisectDevelopment.zip TrisectDevelopment.zip 7.9 KB · Views: 259 Upvote 0
TrisectDevelopment Active Member Licensed User Longtime User May 12, 2014 #6 Strange! Your code Works fine here also. I'll try to compare the code and see if I cant get mine to Work. Thanks for your help Upvote 0
Strange! Your code Works fine here also. I'll try to compare the code and see if I cant get mine to Work. Thanks for your help
TrisectDevelopment Active Member Licensed User Longtime User May 12, 2014 #7 Okay I got it to Work. The difference was download instead of download2 BIG thanks Again. Upvote 0
eps Expert Licensed User Longtime User May 12, 2014 #8 Interesting! What's the difference between the two (apart from one working and the other not...)? Upvote 0
DonManfred Expert Licensed User Longtime User May 13, 2014 #9 job.download uses post-, job.download2 uses get-Methods Edit: Removed my wrong answer due to Erels answer. ;-) Last edited: May 13, 2014 Upvote 0
job.download uses post-, job.download2 uses get-Methods Edit: Removed my wrong answer due to Erels answer. ;-)
Erel B4X founder Staff member Licensed User Longtime User May 13, 2014 #10 I'm afraid that it is not correct. Both Download and Download2 send a GET request. Download2 url encodes the parameters. If there are any parameters then you should use Download2. However the link (first parameter) should not include any parameter and should not include the question mark. Upvote 0
I'm afraid that it is not correct. Both Download and Download2 send a GET request. Download2 url encodes the parameters. If there are any parameters then you should use Download2. However the link (first parameter) should not include any parameter and should not include the question mark.
DonManfred Expert Licensed User Longtime User May 13, 2014 #11 i think i found the error... In #3 i suggested the code Code: Copy nyhedsJob.Initialize("nyhedsJob", Me) nyhedsJob.Download2("http://www.broens-byfest.dk/", Array As String("json", "get_category_posts", "category_slug", "category_slug=Nyheder")) but the last parameter should be "Nyheder" Click to expand... instead of "category_slug=Nyheder" Click to expand... . I did not test it now... Sorry, my mistake Upvote 0
i think i found the error... In #3 i suggested the code Code: Copy nyhedsJob.Initialize("nyhedsJob", Me) nyhedsJob.Download2("http://www.broens-byfest.dk/", Array As String("json", "get_category_posts", "category_slug", "category_slug=Nyheder")) but the last parameter should be "Nyheder" Click to expand... instead of "category_slug=Nyheder" Click to expand... . I did not test it now... Sorry, my mistake