问题:如果包含的功能,我想获得boolean价值trueArrayjsontest1
例子:
{
"features": [
"test1",
"test2",
"test3"
],
"name": "David"
}
Run Code Online (Sandbox Code Playgroud)
对于上面的 json,结果应该是true.
我有一个 Json 格式作为模板(Temp.json)。以下是我的模板格式
{
"products":[
{
"ProductTitleName": "",
"ImageUrl":""
}
]
}
Run Code Online (Sandbox Code Playgroud)
现在我必须将数据填充为这种格式,基本上产品数组将有许多对象节点。我已经使用 JsonPath 表达式从原始 Json 中提取相关属性值。我的问题是如何使用此模板并将数据填充到此结构中。
Reason to use Template Json ——
所以为了避免那些提到的原因,我计划有一个模板 json 并坚持该结构,这是一个好方法,如果是这样,请帮助我将数据填充到模板中,如果没有,请帮助我使用更好的方法。
我有以下格式的 JSON 文件。
{
"queryResponse":[
{
"id":"1",
"name":"Parent1",
"childList":[
{
"id":"11",
"type":"A"
},
{
"id":"12",
"type":"B"
}
]
},
{
"id":"2",
"name":"Parent2",
"childList":[
{
"id":"21",
"type":"B"
},
{
"id":"22",
"type":"C"
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
使用 jayway JsonPath,如何获取所有具有“B”类型子节点的父节点?
这些过滤器表达式返回一个空数组:
唯一最接近我想要的过滤器表达式是带有数组索引的表达式:$.queryResponse[?(@.childList[0].type=='A')]
使用以下 JSON(来自http://jsonpath.com):
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}
Run Code Online (Sandbox Code Playgroud)
仅当 firstName 是 John 时,我才想获取根对象。
我已经尝试过这些输入和许多其他类似的输入:
$.[?($.firstName == 'John')]$.[?($.'firstName' == 'John')]$.[?(@.firstName == 'John')]$[?($.firstName == "John")]似乎过滤仅适用于数组,因此这是一个不受支持的功能。有人知道在 Json.NET 中执行此操作的方法,或者确认这是不可能的,并且可能将我指向支持上述内容的库?
我正在使用 F# 但这并不重要,因为 F# 与 C#、.NET 和 NuGet 包兼容。
我想使用 JsonPath 从 JSON 对象中获取值。有人可以向我建议我需要的适当 jars,因为据我所知,我正在为 jsonpath 使用的 jars 收到此异常。
package jsonPg;
import java.io.IOException;
import org.json.JSONException;
import org.json.JSONObject;
import com.jayway.jsonpath.JsonPath;
public class ReadJsonPath {
static String file = "D:\\AutomationSample\\Sample_Json.txt";
public static void main(String[] args) throws JSONException, IOException {
JsonReadFile jsonReadFile=new JsonReadFile();
JSONObject jsonObj=jsonReadFile.parseJSONFile(file);
String jsonObject=jsonObj.toString();
String json="";
System.out.println(jsonObject);
// Object val = JsonPath.read(jsonObject,"");
String val1=JsonPath.read(jsonObject," $.payload[*].supplierDataMap[*].COMPANYDETAILS.customFieldList[*].DISPLAYGSID .value");
System.out.println(val1);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我编写的代码,下面是运行时抛出的异常
Exception in thread "main" java.lang.NoSuchFieldError: FACTORY_SIMPLE
at com.jayway.jsonpath.spi.impl.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:38)
at com.jayway.jsonpath.spi.impl.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:41)
at com.jayway.jsonpath.spi.JsonProviderFactory.<clinit> (JsonProviderFactory.java:24)
at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:62)
at com.jayway.jsonpath.internal.JsonReader.<init>(JsonReader.java:26)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:462) …Run Code Online (Sandbox Code Playgroud) 我正在使用 MockMVC 测试一个 todo 控制器:
mockMvc.perform(MockMvcRequestBuilders.get("/toDos/")
.with(user("user").password("password").roles("ADMIN"))
.content("{ \"saved_date\": \"2010-01-01\"}")
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect((ResultMatcher) jsonPath("$.id").doesNotExist())
.andExpect(status().isOk())
.andExpect( content().contentType("application/json"));
}
Run Code Online (Sandbox Code Playgroud)
我不断收到此错误:
java.lang.ClassCastException: org.springframework.test.web.client.match.JsonPathRequestMatchers$5 cannot be cast to org.springframework.test.web.servlet.ResultMatcher
Run Code Online (Sandbox Code Playgroud)
我想删除对 (ResultMatcher) 的转换,但不知道如何创建一个 ResultMatcher 来测试 Id 的存在。有任何想法吗 ?
我正在使用 Newtonsoft 的 Json.Net 从以下 json 中选择节点:
{
"projects":[
{
"name":"Project 1",
"client":{
"code":"ABC",
"name":"Client 1"
}
},
{
"name":"Project 2",
"client":{
"code":"DEF",
"name":"Client 2"
}
},
{
"name":"Project 3",
"client":{
"code":"GHI",
"name":"Client 3"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
以下 c# 片段
//json is a JObject representation of the json listed above
var clients = json.SelectTokens("$.projects[*].client");
Run Code Online (Sandbox Code Playgroud)
产量:
[
{
"code":"ABC",
"name":"Client 1"
},
{
"code":"DEF",
"name":"Client 2"
},
{
"code":"GHI",
"name":"Client 3"
}
]
Run Code Online (Sandbox Code Playgroud)
这很酷,现在,我想做的是按客户端代码过滤,我认为
$.projects[*].client[?(@.code == 'DEF')]
Run Code Online (Sandbox Code Playgroud)
会工作,但我显然不太了解语法。这将返回一个空列表:
var test1 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Python 从 JSON 中提取有用信息的不同方法。我尝试了 jsonpath_rw_ext 和 jsonpath_ng。现在我可以使用 jsonpath_rw_ext 但 jsonpath_ng 不起作用。我不想放弃 jsonpath_ng 因为我可能没有以正确的方式使用它。检查以下代码:
import jsonpath_rw_ext
from jsonpath_ng.ext import parse
import json
from pprint import pprint
json_str = '''{
"students": [
{"name": "Peter", "gender": "Male", "age": 20},
{"name": "Mary", "gender": "Female", "age": 30},
{"name": "Susan", "gender": "Female", "age": 40}
],
"teachers": [
{"name": "William", "gender": "Male", "age": 30},
{"name": "John", "gender": "Male", "age": 40},
{"name": "Lucy", "gender": "Female", "age": 50}
]
}'''
json_obj = json.loads(json_str)
print 'jsonpath_rw_ext:'
female_students = jsonpath_rw_ext.match('$.students[?gender=="Female"]', …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我从下面的 json 中检索的 jtoken 设置一个值
{
"Customer":
{
"Id": "100",
"Country": "BE",
"CustomerName": "Domo",
"CustomerStatus": "Gold",
"CreationDate": {
"Time":""
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在设法使用以下 jPath 检索时间令牌:
客户.创建日期.时间
但是在尝试设置属性时获取空值:
var property = timeJToken as JProperty;
property.Value = value;
Run Code Online (Sandbox Code Playgroud) 我正在使用 JSON 并面临一些问题。
我想在 JSON 对象中插入/更新路径。在路径不存在的情况下,它将被创建,然后我插入一个新值。如果它退出,它将被一个新值更新
例如,我想添加这样的新路径:
val doc = JsonPath.parse(jsonString)
doc.add("$.user.name", "John")
Run Code Online (Sandbox Code Playgroud)
但我总是收到此错误,因为路径不存在:
com.jayway.jsonpath.PathNotFoundException 类:路径 $['user'] 中缺少属性
因此,如果它不存在,我想创建一个新路径。
这是我的代码,但jsonString不会改变:
var jsonString = "{}" val conf = Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL).addOptions(Option.SUPPRESS_EXCEPTIONS)
JsonPath.using(conf).parse(jsonString).set(JsonPath.compile("$.user.name"), "John")
Log.d("TAG", "new json = $jsonString")
Run Code Online (Sandbox Code Playgroud)
请给我你的建议。非常感谢!!