美文网首页
convert JSONObject to Map(fastjs

convert JSONObject to Map(fastjs

作者: siyongshuai | 来源:发表于2018-02-24 18:01 被阅读0次

    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(fastjs

          本文链接:https://www.haomeiwen.com/subject/ytlcxftx.html