-2

I'm using websockets, and in the onMessage() method, I'm receiving a response in string form. I want to store this response in model class. How I convert this string response into array list?

[{"sender_id":"0008","created_at":"1313211849934","receiver_id":"0003","message":"second message","id":1,"chat_id":50,"type":"text"},{"sender_id":"0008","created_at":"1519211809934","receiver_id":"0003","message":"second message","id":2,"chat_id":50,"type":"text"}]
1

1 Answer 1

0
class Data {
  var sender_id:String? = null
  var created_at:String? = null
  var receiver_id:String? = null
  var message:String? = null
  var id:Int
  var chat_id:Long
  var type:String? = null
}

val jsonContent = "[{"sender_id":"0008","created_at":"1313211849934","receiver_id":"0003","message":"second message","id":1,"chat_id":50,"type":"text"},{"sender_id":"0008","created_at":"1519211809934","receiver_id":"0003","message":"second message","id":2,"chat_id":50,"type":"text"}]"
val data = new Gson().fromJson(jsonContent, Data:class.java)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.