Android Question JSON Updates to DB server not working !!

SaharJabri

New Member
Dears,

I used to use JRDC to uploading the data to the BD server. But I have this project that I need to use JSON to get/post/update the data. I successfully download the data from the server but while updating the row its not working. in the code it goes as success but in the BD server it is not changing the row.

Here is the code I used for updating:
Json Updates query:
                Dim dcdate As String = rs.GetString("Date")
                Dim dclat As String = rs.GetString("Latitude")
                Dim dclon As String = rs.GetString("Longitude")
                Dim dcstat As String = rs.GetString("DCRCstatus")
                Dim dcfrom As String = rs.GetString("DCRCfrom")
                Dim dcreason As String = rs.GetString("Reason")
                Dim dccommt As String= rs.GetString("Comments")
                Dim dctime As String = rs.GetString("Date") & " " & rs.GetString("Time")
                Dim dcuserid As Int = 265 'rs.GetString("StaffID")
                Dim metread As Int = rs.GetString("ReaderID")
                Dim acno As Int = rs.GetString("AccountNo")
                Dim dcid As Int = rs.GetString("acoID")
               
                '---------------------------------------------------------------------------------
                'convert the photo from file to byte -------------
                '---------------------------------------------------------------------------------
                Dim LocationPic As String = rs.GetString("LocationDCRC")
                Dim BeforeDC As String = rs.GetString("BeforeDC")
                Dim afterDCRC As String = rs.GetString("AfterDCRC")
                Dim MeterPhoto1 As String = rs.GetString("MeterPhoto")
               
                Dim imgloc() As Byte
                If(LocationPic <> "" And LocationPic <> ".png") Then
                    imgloc = FileToBytes(db1.Path,LocationPic)
                End If
                   
                Dim imgbdc() As Byte
                If(BeforeDC <> "" And BeforeDC <> ".png") Then
                    imgbdc = FileToBytes(db1.Path,BeforeDC)
                End If
                   
                Dim imgadc() As Byte
                If(afterDCRC <> "" And afterDCRC <> ".png") Then
                    imgadc = FileToBytes(db1.Path,afterDCRC)
                End If
                   
                Dim imgmet() As Byte
                If(MeterPhoto1 <> "" And MeterPhoto1 <> ".png") Then
                    imgmet = FileToBytes(db1.Path,MeterPhoto1)
                End If
                       

                Dim MapMain As Map = CreateMap ("dcdate": $"${dcdate}"$, "dclat": $"${dclat}"$, "dclon": $"${dclon}"$,"dcstat": $"${dcstat}"$,"dcfrom": $"${dcfrom}"$, "dcreason": $"${dcreason}"$, "dccommt": $"${dccommt}"$,"dctime": $"${dctime}"$,"dcuserid": $"${dcuserid}"$, "metread": $"${metread}"$,"acno": $"${acno}"$,"dcid": $"${dcid}"$,"imgmet": $"${imgmet}"$, "imgbdc": $"${imgbdc}"$, "imgadc": $"${imgadc}"$,"imgloc": $"${imgloc}"$)
                JSONGenerator.Initialize(MapMain)
                Log(JSONGenerator.ToPrettyString(5).Replace("\", "").Replace("""[", "[").Replace("]""", "]")) 'REMOVE UNNECESSARY CHARACTERS

                'Post request for ticker data via the JSON generated string
                Dim J As HttpJob
                J.Initialize(Null, Me)
                J.PostString($"https:Link"$, JSONGenerator.ToString.Replace("\", "").Replace("""[", "[").Replace("]""", "]")) 'REMOVE UNNECESSARY CHARACTERS
   
                J.GetRequest.SetContentType("application/json; charset=utf-8")


                Wait For (J) JobDone(j As HttpJob)
                Log(J.Success)

                If J.Success Then
                    Log("Success")
'                    Log("J.GetString: " & J.GetString)
                Else
                    Log("Error")
                    ToastMessageShow("There is a problem in the connection, Please check your internet !!", True)
                End If

is there is any problem in my code?? or there is another way to do it.
 
Last edited:

SaharJabri

New Member
1. Why are you shouting in the thread title? No one will want to help you if you shout.
Am not ?, Sorry if its seem like that.

2. Very strange code. Why do you replace anything in the generated json string? It generates valid strings.
I used the same code as getting data from the server database. should I don't replace in the parser? it is my first time using json in B4A

3. What is BD server?
I main the database in the server side. the row is not updating when I use the code.
 
Upvote 0

SaharJabri

New Member
Am trying to get the data from the server and then updates the row after specific action using JSON.
the getting data is working fine. But updating in an existed row is not works with me. I don't get any error.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
should I don't replace in the parser? it is my first time using json in B4A
Why should you replace anything? The json generator will never generate invalid json.


But updating in an existed row is not works with me. I don't get any error.
The client sends json string. You should check your server code.

Best option is to use jRDC2.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
The JSON format is for exchange purposes (any platform can handle it). As Erel mentioned, don't remove anything. Format it to a simple string (not pretty).

"[" starts a list (or array) "{" a map.

Are you sending the JSON string to a php script?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…