Json:scala解析json字符串,获取多级key(2):希望下面的文章对大家有所帮助。 import com.alibaba.fastjson.JSON /** * Created by yuhui on 2016/12/20. */ object Test{ def main(args: Array[String]): Unit = { val json = "{\"user_details\":{\"data_column\":\"suuid\"},\"fliter\":{\"event\":\"where event='PageView' or event='ExEvent' or event='Consumption'\"}}" //获取一级key,以及值 println(JSON.parseObject(JSON.parseObject(json).get("user_details").toString)) //获取二级key,以及值 println(JSON.parseObject(JSON.parseObject(json).get("user_details").toString).get("data_column").toString) //获取一级key,以及值 println(JSON.parseObject(JSON.parseObject(json).get("fliter").toString)) //获取二级key,以及值 println(JSON.parseObject(JSON.parseObject(json).get("fliter").toString).get("event").toString) } }
运行结果:
{"data_column":"suuid"} suuid {"event":"where event='PageView' or event='ExEvent' or event='Consumption'"} where event='PageView' or event='ExEvent' or event='Consumption'