0

Parsing the value from JSON and stored it into a variable using Groovy. below is the value stored in that variable.

[[UserName:usernameX, Password:passwordX]]

The format is Arraylist, how can I retrieve the UserName and Password value like [usernameXand passwordX].

2 Answers 2

1

Hmmm, double [[]] and no quotes. I don't know how your data gets into an ArrayList, but if you can get the data in a Groovy Map, you can do it like this:

Map a = ['UserName':'usernameX', 'Password':'passwordX']

a.each { k, v ->
    println v
}

prints:

usernameX
passwordX
Sign up to request clarification or add additional context in comments.

Comments

0

You can convert the nested array-list straight into a map:

Map map = [[UserName:'usernameX', Password:'passwordX']].collectEntries{ [ it.UserName, it.Password ] }

assert map == [usernameX:'passwordX']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.