I am trying to get name from logged In user Session and display it on a textview from the following code snippet.
private void getUserName(){
client = new Client(requireActivity())
.setEndpoint(endpoint)
.setProject(project);
account = new Account(client);
account.getSession("current",
new CoroutineCallback<>((result, error)-> {
if (error != null) {
error.printStackTrace();
}else{
// pass `result` in to a json object
try {
JSONObject jsonObject = new JSONObject(String.valueOf(result));
//get parameter "name" from the json object
String name = jsonObject.getString("name");
// pass the name parameter into textview
binding.userNameDisplay.setText(name);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
));
}
I get this exception Error
org.json.JSONException: Value Session(id of type java.lang.String cannot be converted to JSONObject
can you log the result to check its shape
which lang is that?
Java. I did the log. Its is not in JSON. Weird stuff. they is no name feild. But i can see the user name on the appwrite console. All i can see on the log is id createdAt etc
can you show me the output
android sdk?
JSON Error syc...scan E The result string is not a valid JSON object: Session(id=643664af54b3546543bf, createdAt=2023-04-12T07:58:39.350+00:00, userId=643612e4b8d495e5f32a, expire=2024-04-11 07:58:39.350, provider=email, providerUid=********, providerAccessToken=, providerAccessTokenExpiry=, providerRefreshToken=, ip=********, osCode=AND, osName=Android, osVersion=12, clientType=browser, clientCode=AN, clientName=Android Browser, clientVersion=, clientEngine=WebKit, clientEngineVersion=, deviceName=smartphone, deviceBrand=Samsung, deviceModel=SM-A136B, countryCode=--, countryName=Unknown, current=true)
noo, just the result before parsing it
Session(id=643674b62e1330fa1564, createdAt=2023-04-12T09:07:02.501+00:00, userId=Sam, expire=2024-04-11 09:07:02.501, provider=email, providerUid=*****************, providerAccessToken=, providerAccessTokenExpiry=, providerRefreshToken=, ip=************, osCode=AND, osName=Android, osVersion=12, clientType=browser, clientCode=AN, clientName=Android Browser, clientVersion=, clientEngine=WebKit, clientEngineVersion=, deviceName=smartphone, deviceBrand=Samsung, deviceModel=SM-A136B, countryCode=--, countryName=Unknown, current=true)
Its still same log
there's a toString() method for the result object according to this can you try that
https://appwrite.io/docs/client/account?sdk=android-java#accountGetSession
Recommended threads
- {"code": 1008, "message": "Invalid Origi...
Nothing has changed in my application or console settings so I'm curious as to what I need to do to fix this. I already have the client registered so I'm not en...
- android platform invaild origina
It happened today suddenly. Our app says invalid origin. And appwrite cloud says every time we tried to add the app to it: "param platformId" is not optional.
- All my apps are not opening now
All my apps are not opening now 200+ apps are not opening plz fast