String jsonString = "{"code":200,"data":{"list":[{"buyerId":3132211,"buyerName":"","buyerPhoneNo":"","createTime":1552632827696,"headCount":1,"id":639,"itemList":[{"alias":"aaddasss","imageUrl":"1111","itemId":2313,"kdtId":1231,"num":1,"price":300,"sku":"[{"k":"房型","k_id":542,"v":"22222","v_id":11111}]","skuId":10622255,"title":"陈达测试多规格--陈达"}],"kdtId":33333333,"kdtName":"","orderNo":"E2232","orderStatus":100,"orderType":1,"payablePrice":120,"remark":"","seatName":"311111111","serialNo":"1","storeId":0}],"page":1,"pageSize":20,"totalItems":246},"message":"successful","success":true}";
System.out.println(JSONPath.read(jsonString,"$.data.list[0].itemList[0].sku[0].v"));
Exception in thread "main" java.lang.UnsupportedOperationException
at com.alibaba.fastjson.JSONPath.getArrayItem(JSONPath.java:1584)
at com.alibaba.fastjson.JSONPath$ArrayAccessSegement.eval(JSONPath.java:1093)
at com.alibaba.fastjson.JSONPath.eval(JSONPath.java:80)
at com.alibaba.fastjson.JSONPath.read(JSONPath.java:306)
Exception:
1条答案
按热度按时间pu82cl6c1#
你这个应该是不行的吧,sku对应的value是一个字符串,字符串内的内层JSON元素根本就不在外层JSON对象的层次结构中。要达到你的目的,可以这么写: