0
我想使用com.jayway.jsonpath.JsonPath從JSON字符串讀取鍵/值:com.jayway.jsonpath.JsonPath找不到鑰匙
String contentAsString = mvcResult.getResponse().getContentAsString();
System.out.println(contentAsString);
Object value = JsonPath.read(contentAsString, "$.key");
但我得到的錯誤:
Expected to find an object with property ['key'] in path $ but found 'net.minidev.json.JSONArray'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
印刷contentAsString
給出:
[{"firstName":"N","key":"mykey"}]
是contentAsString
無效的JSON?