Scala中的MutableList到JSON

时间:2015-12-04 16:50:20

标签: json list scala

我以这种方式使用ListBuilder构建了一个MutableList:

Vector("MM_2015_2_EC_13,MM_2015_2_EC_19,.........)

我想要检索这样的JSON:

{"ec":
  ["MM_2015_2_EC_13",
  "MM_2015_2_EC_19",
  "MM_2015_2_EC_23",
  "MM_2015_2_EC_29",
  "MM_2015_2_EC_43",
  "MM_2015_2_EC_53",
  "MM_2015_2_EC_59",
  "MM_2015_2_EC_62",
  "MM_2015_2_EC_63",
  "MM_2015_2_EC_64",
  "MM_2015_2_EC_69",
  "MM_2015_2_EC_73",
  "MM_2015_2_EC_75",
  "MM_2015_2_EC_76",
  "MM_2015_2_EC_78",
  "MM_2015_2_EC_88",
  "MM_2015_2_EC_93",
  "MM_2015_2_EC_96",
  "MM_2015_2_EC_98",
  "MM_2015_2_EC_99"],
"pos":
      ["MM_PS_1000123018"],
"yearSeason":
      "2015_2",
"orderType":"2B"}

抱歉,我是Scala的新手,我无法解决这个问题。

1 个答案:

答案 0 :(得分:1)

使用play.api.libs.json库(参见play doc),您可以这样做:

JsArray(Vector(...).map{v=>
  JsString(v)
})

(未经测试)