Hi,
I am trying to parse the json output from a httppost.
here’s my code :
def auth() {
def params = [
uri: "https://accounts.api.anki.com",
path: "/1/sessions",
headers: ["User-Agent": "f'Vector-sdk/{anki_vector.__version__}'", "Anki-App-Key": "aung2ieCho3aiph7Eexxxx"],
body: [
username: "test@gmail.com",
password: "testtest"
]
]
def result = [:]
try {
httpPost(params) { resp ->
resp.headers.each {
log.debug "${it.name} : ${it.value}"
}
log.debug "response contentType: ${resp.contentType}"
log.debug "response : ${resp.data}"
result="${resp.data}"
log.debug $sonuc
}
} catch (e) {
log.debug "something went wrong: $e"
}
}
the log output is like:
4e37b388-b4e2-429e-b434-ea521a70dddd 12:53:09 AM: debug response : {“session”:{“session_token”:“2xxxPvzAaj3n6Ejmwjd3xxx”,“user_id”:“2xxx2CH3TxxxxpJStrqptVC”,“scope”:“user”,“time_created”:“2018-12-15T21:53:09.582712433Z”,“time_expires”:“2019-12-15T21:53:09.582699756Z”},“user”:{“user_id”:“2xxx2CH3T5JxxxJStrqptVC”,“drive_guest_id”:“axxxce22-16d6-4afc-be77-e250dd286be1”,“player_id”:“axxxce22-16d6-4afc-be77-e250dd286be1”,“created_by_app_name”:“chewie”,“created_by_app_version”:“1.1.1”,“created_by_app_platform”:“android 8.1.0; samsung SM-N960F",“dob”:“1976-05-10”,“email”:"test@gmail.com",“family_name”:null,“gender”:null,“given_name”:null,“username”:"test@gmail.com”,“email_is_verified”:true,“email_failure_code”:null,“email_lang”:“en-US”,“password_is_complex”:true,“status”:“active”,“time_created”:“2018-11-08T14:04:03Z”,“deactivation_reason”:null,“purge_reason”:null,“email_is_blocked”:false,“no_autodelete”:false,“is_email_account”:true}}
4e37b388-b4e2-429e-b434-ea521a70dddd 12:53:09 AM: debug response contentType: text/json
4e37b388-b4e2-429e-b434-ea521a70dddd 12:53:09 AM: debug Connection : keep-alive
4e37b388-b4e2-429e-b434-ea521a70dddd 12:53:09 AM: debug Vary : Accept-Encoding
4e37b388-b4e2-429e-b434-ea521a70dddd 12:53:09 AM: debug Vary : Origin
4e37b388-b4e2-429e-b434-ea521a70dddd 12:53:09 AM: debug Date : Sat, 15 Dec 2018 21:53:09 GMT
4e37b388-b4e2-429e-b434-ea521a70dddd 12:53:09 AM: debug Content-Type : text/json
4e37b388-b4e2-429e-b434-ea521a70dddd 12:53:09 AM: debug Anki-Request-Id : 95u2qjct6mdddx8ajp6xyjtr
here, I want to get the session->session_token by parsing the data from response.
However I could not parse it. If I try to read as “resp.data.session.session” it complains that this is a byteArrayInputStream
how can I get the “session_token” here ?