Android Question Reading JSON datetime

luisro

Member
Licensed User
hi, Could the following problem help me, I make a sql query of certain fields and the date field throws me the following...

B4X:
{date=2014-11-11 17:38:44, timezone_type=3, timezone=Europe/Berlin}

Of all this chain that is stored in a variable I would like to take only DATE = 2014-11-11 17:38:44
Specifically only 2014-11-11 17:38:44

B4X:
Sub ejecutar_consulta4(Query As String,JobName As String)
    Dim job As HttpJob
    job.Initialize (consultar, Me)
    job.PostString("XXXXXXXXX:XXX:XXX:XXX:XX:X", Query)
End Sub

Sub jobDone (job As HttpJob)
    ProgressDialogHide
    If job.Success Then
        Dim res As String
        res = job.GetString
        Dim parser As JSONParser
        parser.Initialize(res)
        Select job.JobName
            
               Case consultar
                Dim list1 As List
                list1 = parser.NextArray
                For i = 0 To list1.Size -1
                    Dim m As Map
                    m = list1.Get(i)
                    log(m)
                    Dim y As Y
                    y.y1= m.Get("ID")' numero ID
                    y.y2= m.Get("Fecha") 'fecha de emision
    Next
        End Select
    Else
        ToastMessageShow("Error de conexion", True)
    End If
    job.Release
End Sub

I can not find a JSON string value inside the JSON String of the established query

(MyMap) {ID=00000, FechaE={date=2017-05-31 11:34:11, timezone_type=3, timezone=Europe/Berlin}
 

DonManfred

Expert
Licensed User
Longtime User
{date=2014-11-11 17:38:44, timezone_type=3, timezone=Europe/Berlin}
This is not a proper formatted json

{date="2014-11-11 17:38:44", timezone_type=3, timezone="Europe/Berlin"}
It should look like this.
B4X:
Dim parser As JSONParser
parser.Initialize($"{date="2014-11-11 17:38:44", timezone_type=3, timezone="Europe/Berlin"}"$)
Dim root As Map = parser.NextObject
Dim date As String = root.Get("date")
Dim timezone As String = root.Get("timezone")
Dim timezone_type As Int = root.Get("timezone_type")
 
Upvote 0

luisro

Member
Licensed User
The string that does not have the correct format is in y.y2, I explain, if my intention is to load a list of data with their dates, would be several y.y2 (As I modify the format so that all have the correct) if Other than to vary are many.
Other part of the code:

B4X:
Sub ListView1_ItemClick (Position As Int, Value As Object)
    Dim y As Y
    y = Value
label1.text = y.y1
label2.text=y.y2

End Sub

Explain to me..
 
Last edited:
Upvote 0

eps

Expert
Licensed User
Longtime User
Something like this?

B4X:
Dim parser As JSONParser 
parser.Initialize(<text>) 
Dim root As Map = parser.NextObject 
Dim FechaE As Map = root.Get("FechaE") 
Dim date As String = FechaE.Get("date") 
Dim timezone As String = FechaE.Get("timezone") 
Dim timezone_type As String = FechaE.Get("timezone_type") 
Dim ID As Int = root.Get("ID")

From using this : http://basic4ppc.com:51042/json/index.html

Maps vs Lists.... https://www.b4x.com/android/forum/threads/jsontree-tool-to-help-with-json-parsing-b4a-b4j.35963/

HTH
 
Upvote 0
Top