user12340963
user12340963

Reputation:

How to get a key value from a LinkedHashMap

I am trying to retrieve a LinkedHashMap key value, but I do not find any coherent solution for my problem, I am using firebase power to download the content for the LinkedHashMap but I do not any solution for retrieving the Question key value of the LinkedHashMap named d

I have this code:

linkedHashMapForLessonContent = (intent.getSerializableExtra(tags?.LESSON_MAP_TAG_NAME) as WrapperSerializer<LinkedHashMap<String, Any>>).get() as LinkedHashMap<String, Any>

Which returns a LinkedHashMap with the keys: {0={...}, 1={...}, 2={...}, 3={...}, 4={...}...} Then I try to get the "0" value this way

var d = (linkedHashMapForLessonContent as LinkedHashMap<String, Any>)["0"]
Log.e("d", d.toString())

which returns

{Question=What is Gravity?, Content=[https://firebasestorage.googleapis.com/someimage0, https://firebasestorage.googleapis.com/someimage1, https://firebasestorage.googleapis.com/someimage2, https://firebasestorage.googleapis.com/someimage3], Type=Images, Answer=0}

So I want to return the value of the Question as the following

Log.e("hello world", something to get the question value)

That will return

'What is Gravity?'

I have tried multiple solutions and searched multiple things but no thing has the answer for my problem, I would be thankful if someone helps me out with this :) Thank you

Upvotes: 0

Views: 557

Answers (1)

AliSh
AliSh

Reputation: 10649

You should convert d.toString() to a JSON then get "question" value:

JSONObject(d.toString())["question"].toString()

Upvotes: 0

Related Questions