count members with jsonpath?

前端 未结 5 1077
生来不讨喜
生来不讨喜 2020-12-22 20:42

Is it possible to count the number of members using JsonPath?

Using spring mvc test I\'m testing a controller that generates

{\"foo\": \"oof\", \"ba         


        
5条回答
  •  一整个雨季
    2020-12-22 21:13

    if you don't have com.jayway.jsonassert.JsonAssert on your classpath (which was the case with me), testing in the following way may be a possible workaround:

    assertEquals(expectedLength, ((net.minidev.json.JSONArray)parsedContent.read("$")).size());
    

    [note: i assumed that the content of the json is always an array]

提交回复
热议问题