Android Question httputils2 strange behavour

Discussion in 'Android Questions' started by jayel, Mar 15, 2015.

  1. jayel

    jayel Active Member Licensed User

    Hello,

    When I use the httputils2 to send and receive data from my testserver local, everything works.
    I uploafd my php file to my webhosting and the same code gives me an error on decoding Json :
    Can somebowy help me ?
     
  2. DonManfred

    DonManfred Expert Licensed User

    What is the exact output of
    Code:
    log(Job.GetString)
    in sub JobDone?
     
  3. jayel

    jayel Active Member Licensed User

     
  4. DonManfred

    DonManfred Expert Licensed User

    if that is really the output from you phpscript then it should work.

    Show your JobDone sub code to see more...
     
  5. jayel

    jayel Active Member Licensed User

    Code:
    Sub JobDone (Job As HttpJob)
      
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
      
    If Job.Success = True Then
          
    Select Job.JobName
           
            
    Case "getcountwerkengepauzeerd"
                
    Dim mystr As String
                mystr = Job.GetString
                
    If mystr <> "" Then
                    CheckJSON(mystr,Job.JobName)
                   
                
    End If
               
            
    Case "getcountgeplandewerken"
                
    Dim mystr As String
                mystr = Job.GetString
                
    If mystr <> "" Then
                    CheckJSON(mystr, Job.JobName)
                   
                
    End If
            
          
    End Select
      
    Else
          
    Log("Error: " & Job.ErrorMessage)
          
    ToastMessageShow("Error: " & Job.ErrorMessage, True)
      
    End If
      Job.Release
    End Sub
    CheckJson
    Code:
    Sub CheckJSON(AantalSTR As String, jobname As String )
        
    Log(AantalSTR)
       
        
    Dim myJson As JSONParser

        myJson.Initialize(AantalSTR)
        
    Dim map1 As Map
        map1 = myJson.nextobject 
    '<--- error here
        Dim errorstr As String
        errorstr = map1.Get(
    "error")
        
    Dim tag As String
        tag = map1.Get(
    "tag")
       
        
    If errorstr = "false" Then
            
    Dim aantal As String
            aantal = map1.Get(
    "result")
            
    Select Case jobname
                
    Case "getcountwerkengepauzeerd"
                    UpdateBadgeWerkenGepauzeerd(aantal)
                    GetGeplandeWerken
                
    Case "getcountgeplandewerken"
                    UpdateBadgeGeplandeWerken(aantal)
                    
    ProgressDialogHide
                   
            
    End Select
           
    '        If aantal <> "0" Then
    '            UpdateBadgeWerkenGepauzeerd(aantal)
    '        End If
        Else
            
    Dim myerrormsg As String
            myerrormsg = map1.Get(
    "error_msg")
            
    ToastMessageShow(myerrormsg, True)
           
       
        
    End If
       
       
    End Sub
     
  6. DonManfred

    DonManfred Expert Licensed User

    This code should work to read your result
    Code:
    Dim parser As JSONParser
    parser.Initialize(<text>)
    Dim root As Map = parser.NextObject
    Dim result As Int = root.Get("result")
    Dim error As String = root.Get("error")
    Dim tag As String = root.Get("tag")
    See it here online.
     
  7. jayel

    jayel Active Member Licensed User

    No, it give the same error.

    Code:
    Dim parser As JSONParser
        parser.Initialize(AantalSTR)
        
    Dim root As Map = parser.NextObject '<-- error here     
        Dim error As String = root.Get("error")
        
    Dim tag As String = root.Get("tag")
        
    Dim result As Int = root.Get("result")
     
  8. DonManfred

    DonManfred Expert Licensed User

    can you upload a small eexample project which shows this error (including your url to the php you are using)?
     
  9. jayel

    jayel Active Member Licensed User

    Hello,

    Just made a small example, can I send you a mail with my testproject?
     
  10. DonManfred

    DonManfred Expert Licensed User

  11. jayel

    jayel Active Member Licensed User

    I have send you a small project.
    Could you confirm that you received the file?
     
  12. DonManfred

    DonManfred Expert Licensed User

    Confirmed; see pn for more info
     
  13. jayel

    jayel Active Member Licensed User

    Hello,

    So after a whole day trying with Manfred (many thanks), we didn't find the solution.
    on my hosting the return Json was rapped arround a <pre> tag.
    HTML:
    <pre style="word-wrap: break-word; white-space: pre-wrap;">{"tag":"getcountwerkengepauzeerd","error":false,"result":7}</pre>
    I wanted just the json....
    I managed to remove the <pre> tag with this on the top of my php code :
    PHP:
    header('Content-Type: text/html')
    Now I don't have the <pre> tag but 3 empty chars on the beginning of my script.
    When I remove the empty chars my output works, but that is not the way to go....

    What am i missing here ??
     
  14. jayel

    jayel Active Member Licensed User

    Hello,

    Just to avoid that somebody else has the same issue.
    The 3 characters in the beginning are ascii = 65279
    These are BOM characters.
    I was using a php extension for visual studio to write my php code, now it seems that when you use include or require it put a BOM character.
    When I use Notepad++ then I can save UTF8 without BOM and everything works.
    see : http://stackoverflow.com/questions/41647/php-include-function-outputting-unknown-char

    Many thanks to Manfred for the help !
     
    DonManfred likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice