ich versuche gerade eine JSON Antwort von einem Server zu parsen, aber irgendwie stelle ich mich da zu doof an
Evtl. kann mir da ja mal jemand auf die Sprünge helfen? Es geht um folgende JSON Struktur:
Code: Alles auswählen
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJJbm9Db3JlIiwiaWF0IjoxNjUyNjc0MzY2LCJleHAiOjE2NTI2Nzc5NjYsImF1ZCI6InB1cmViYXNpY0Bsb2NhbGhvc3QiLCJ1aWQiOjh9.q66RWqH3iBJsCuAdJ_XCLjWSj7i3BJhs3gmB4MC1KBk",
"expires": {
"date": "2022-05-16 07:12:46.098796",
"timezone_type": 3,
"timezone": "Europe/Berlin"
},
"user": {
"id": 8,
"email": "purebasic@localhost",
"firstname": "Pure",
"lastname": "Basic",
"login_count": 115,
"last_login": "2022-05-16 06:12:29.409009",
"failed_login_date": null,
"create_date": "2022-05-15 22:23:11.800488",
"is_daemon": 0
}
}
Meine bisherigen Ansätze scheitern immer daran, dass einige Felder leer sind??
Hier mein Code:
Code: Alles auswählen
Structure ICTExpires
date.s
timezone_type.l
timezone.s
EndStructure
Structure ICTUser
id.l
email.s
firstname.s
lastname.s
login_count.l
last_login.s
failed_login_date.s
create_date.s
is_daemon.l
EndStructure
Structure ICT
token.s
Map expires.ICTExpires()
Map user.ICTUser()
EndStructure
HttpRequest = HTTPRequest(#PB_HTTP_Post,BASE$, "["+Chr(34)+"todo.all"+Chr(34)+"]", #PB_HTTP_Debug|#PB_HTTP_NoSSLCheck, Header$());
If HttpRequest
HttpCode.s = HTTPInfo(HTTPRequest, #PB_HTTP_StatusCode)
HttpResponse = HTTPInfo(HTTPRequest, #PB_HTTP_Response)
FinishHTTP(HTTPRequest)
ParseJSON(0,HttpResponse)
ObjectValue = JSONValue(0)
NewMap Expires.ICTExpires()
NewMap User()
NewMap UL.ICTUser()
NewMap ICT.ICT()
Token.s = GetJSONString(GetJSONMember(JSONValue(0),"token"))
ExtractJSONMap(JSONValue(0),ICT())
Debug ICT()\expires()\date
ExtractJSONMap(GetJSONMember(JSONValue(0),"expires"),Expires())
ExtractJSONMap(GetJSONMember(JSONValue(0),"user"),User())
ExtractJSONMap(GetJSONMember(JSONValue(0),"user"),UL())
Debug "DATE: " + Expires()\date
Debug "TZ-TYPE: " + Expires()\timezone_type
Debug "TZ: " + Expires()\timezone
;Debug user("email")
;Debug Token
Else
Debug "Request creation failed"
EndIf
Debug "---------------------------------------------"
Debug(HttpResponse);
Nutze ich "ExtractJSONMap(GetJSONMember(JSONValue(0),"user"),User())" - also eine leere Map - sind alle Integer Fields leer.
Definiere ich die Map "User()" als "User.s()", sind die Textfields vorhanden, dafür aber die Integerfelder nicht mehr?
Kann mir da evtl. mal jemand helfen, meinen Knoten im Kopf zu lösen?
Vielen Dank schon mal im Vorraus!