2013-08-20 3 views
2

Readme https://github.com/json4s/json4s#linq-style 의 예제에서 다음 테스트를 실행하려고했지만 빈 목록이 표시됩니다. 나는 결과가 없다 예제에서 지정된 목록 (5, 3)Json4s 'linq-style'for-comprehension 빈 목록 제공

test("JValue with for comprehension") { 
    import org.json4s._ 
    import org.json4s.native.JsonMethods._ 

    val json = parse(""" 
    { "name": "joe", 
     "children": [ 
     { 
      "name": "Mary", 
      "age": 5 
     }, 
     { 
      "name": "Mazy", 
      "age": 3 
     } 
     ] 
    } 
        """) 

    val result = for {JField("age", JInt(age)) <- json} yield age 
    println(result) 

    //Output : List() 
    } 

답변

2

OK 문제를 발견했습니다. json에서 JObject를 생성하려면 먼저 생성기 절을 추가해야합니다.

val result = for { JObject(child) <- json 
        JField("age", JInt(age)) <- child} 
      yield age 
//Output : List(5, 3)