convert JSONObject to Map(fastjson)

val fidsjson = """

{ "msg": "success", "code": "00", "result": [{ "fgId": 205, "fgIndex": 1, "fgType": 0 }, { "fgId": 197, "fgIndex": 2, "fgType": 1 }] }

"""

val map = JSON.parseObject(fidsjson).asScala.toMap[String,Any]

val map2 = JSON.parseObject(fidsjson).getJSONArray("result").asScala.toList.map(x => x.asInstanceOf[JSONObject].asScala.toMap[String,Any])

the map is:

Map(msg -> success, result -> [{"fgId":205,"fgIndex":1,"fgType":0},{"fgId":197,"fgIndex":2,"fgType":1}], code -> 00)

the map2 is :

List(Map(fgId -> 205, fgIndex -> 1, fgType -> 0), Map(fgId -> 197, fgIndex -> 2, fgType -> 1))


core class

scala.collection.JavaConverters.asScala

你可能感兴趣的:(convert JSONObject to Map(fastjson))