Android Question How do I see the contents of my JSON String?

davepamn

Active Member
Licensed User
Longtime User
I need to inspect in debug my json string returning from the server.

The debug "copy to clipboard" truncates the data.

The JSON parser seems to throwing away some rows in the JSON string

B4X:
Sub HandleContracts(Job As HttpJob)

    If Job.Success = False Then
        ToastMessageShow("Error downloading data.", True)
        ProgressDialogHide
        Return
    End If

    Dim TextReader1 As TextReader
    TextReader1.Initialize(Job.GetInputStream)

    Dim Text As String
    Text = StripTags(TextReader1.ReadAll )

     Dim p AsJSONParser
      RowMap.Initialize
      TableList.Initialize
      p.Initialize(Text)

end sub

Sub StripTags(sJSON As String) As String

    Dim Text As String=""
    Text = sJSON
    Do While Text.IndexOf(">")>0
             Dim StartTag As Int
             Dim EndTag As Int
            StartTag=Text.IndexOf("<")
            EndTag=Text.IndexOf(">")+1
            Dim S As StringBuilder
            S.Initialize
            S.Append(Text)
            S=S.Remove(StartTag,EndTag)
            Text=S.ToString
        Loop
    Return(Text)

End Sub
 

davepamn

Active Member
Licensed User
Longtime User
My program is getting the json string out of debug. I may try and write it to a text file
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I may try and write it to a text file
or you may change the server side and just return less data so you can see the hole answer in the logs, copy it into the jsontree tool to create the b4a code for you
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
I need to inspect in debug my json string returning from the server.

The debug "copy to clipboard" truncates the data.

The JSON parser seems to throwing away some rows in the JSON string

Where you want to inspect the string, insert this line:
B4X:
File.WriteString(File.DirDefaultExternal, "myfile.txt")

Run the program and then you can inspect myfile.txt file with the complete string.
You can also copy myfile.txt from device to a PC and open it with your editor

Sergio
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
B4X:
File.WriteString(File.DirDefaultExternal,"myFile.txt",myJSONString)

I was able to inspect the json string using a tablet editor.
 
Last edited:
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
or you may change the server side and just return less data so you can see the hole answer in the logs, copy it into the jsontree tool to create the b4a code for you

I was able to shorting the json string but it still exceed 4000 characters. In my opinion, b4a needs to improve the debug capabilities and features.
 
Upvote 0
Top