简体   繁体   中英

Scala: Zip two lists into json array format

I have two lists that look like this:

List("key1", "key2")
List("val1", "val2")

I'm trying to get it into this JSON-like format:

[{"key1":"val1"},{"key2","val2"}]

Right now, this is what I'm using:

val output = List(attrKeys.zip(attrValues).toMap)

But it gives me this:

[{"key1":"val1","key2":"val2"}]

How do I get this into a list of separate map objects?

attrKeys.zip(attrValues).map(Map(_))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM