Jackson Json访问JsonNode属性名称(Jackson Json accesing JsonNode property name)
我有这样的架构:
{ "type" : "object", "$schema" : "http://json-schema.org/draft-03/schema#", "id" : "urn:jsonschema:com:vlashel:dto:UserDto", "description" : "this is the top description", "title" : "this is the top title", "properties" : { "number" : { "type" : "integer" "required" : true }, "password" : { "type" : "string" "required" : true } }
我有以下代码通过删除“required”将此shcema draft 3转换为draft 4,我想收集其中包含'requred'的节点属性名称。 我怎么做? 我没有看到这方面的方法..
JsonNode jsonNode = jsonNodeIterator.next(); ObjectNode element; if (jsonNode instanceof ObjectNode) { element = (ObjectNode) jsonNode; element.remove("required"); String propertyName = element.getPropertyName(); //I'm looking for this kind of method.
谢谢!
I have a schema like this:
{ "type" : "object", "$schema" : "http://json-schema.org/draft-03/schema#", "id" : "urn:jsonschema:com:vlashel:dto:UserDto", "description" : "this is the top description", "title" : "this is the top title", "properties" : { "number" : { "type" : "integer" "required" : true }, "password" : { "type" : "string" "required" : true } }
I have the following code that converts this shcema draft 3 to draft 4 by removing "required", I want to collect nodes property names that have 'requred' in them. How do I do that? I don't see methods for this..
JsonNode jsonNode = jsonNodeIterator.next(); ObjectNode element; if (jsonNode instanceof ObjectNode) { element = (ObjectNode) jsonNode; element.remove("required"); String propertyName = element.getPropertyName(); //I'm looking for this kind of method.
Thanks!
原文:https://stackoverflow.com/questions/26108156
最满意答案
您不必使用foreach迭代对象,因为'age'是
$data->faceAttributes
一个属性。改用它
if (count($data->faceAttributes)) { echo $data->faceAttributes->age; echo $data->faceAttributes->gender; }
但是,
$data
是一个数组,您使用的$data[0]
实际上是$data[0]
所以,如果数据数组中只有一个元素,你可以这样做
$data = $data[0] or $data = json_decode($json)[0]
或者,如果多于一个元素,则可以遍历
$data
。You don't have to iterate the object using foreach as the 'age' is a property of
$data->faceAttributes
itself.Use this instead
if (count($data->faceAttributes)) { echo $data->faceAttributes->age; echo $data->faceAttributes->gender; }
However,
$data
is an array and which$data
you are using is actually$data[0]
So, if there is only one element in data array you can do
$data = $data[0] or $data = json_decode($json)[0]
Or, you can iterate through
$data
in case of more then one element.
相关问答
更多-
空响应php sql json(empty response php sql json)[2022-11-28]
这是你的最终代码吗? 如果发生连接错误消息,您不会输出任何内容。 更改 $json = json_encode($results); 至 echo json_encode($results); 如果它仍为空白,则可能是数据库数据问题。 Is this your final code? You are not outputting anything apart from the connection error message if it happens. Change $json = json_e ... -
您可以使用.each遍历对象: $.getJSON("controllers/Customer.controller.php", param, function(json){ // loop over each object in the array // 'i' is the index of the object within the array // 'val' (or this) is the actual object at that offset $.each( ...
-
JSON / PHP - 空数组(JSON/PHP - Empty Array)[2022-02-14]
有些数据库对象是西班牙文的,最有可能的是你的结果数组$arreglo没有用$arreglo -8编码。 由于西班牙语使用特殊字符如'ñ',所以很可能您的默认数据库编码不是utf-8。 遇到这种字符时,函数json_encode失败并不显示任何内容。 因为这个函数只能用于utf-8的结果。 处理这个问题的一个方法是通过这个函数传递数组,以便将所有内容都转换为utf-8。 将以下函数添加到您的PHP。 function cast_data_types ($value) { if (is_array ... -
您不必使用foreach迭代对象,因为'age'是$data->faceAttributes一个属性。 改用它 if (count($data->faceAttributes)) { echo $data->faceAttributes->age; echo $data->faceAttributes->gender; } 但是, $data是一个数组,您使用的$data[0]实际上是$data[0] 所以,如果数据数组中只有一个元素,你可以这样做 $data = $data[0] ...
-
请参阅: http : //php.net/manual/en/function.exec.php#116222 无法从exec'd命令获取输出以显示在$ output数组中? 相反,它是否反映在你的外壳上? 在命令末尾附加“2>&1”,例如: exec("xmllint --noout ~/desktop/test.xml 2>&1", $retArr, $retVal); 将使用预期输出填充数组$ retArr; 每个数组键一行。 See: http://php.net/manual/en/functi ...
-
你只需要使用第二个参数设置为TRUE json_decode() 。 $str = '...'; $json = json_decode($str, TRUE); $artist = $json['response']['artists']; //$artist = json_decode($str, TRUE)['response']['artists']; as of PHP 5.4 print_r($artist); 输出: Array ( [0] => Array ...
-
如果你想要它作为一个数组,你需要使用它 $array = json_decode($var, true); 否则,它将返回json作为对象而不是数组 这样做应该让你像这样访问它: $fl = $array[0]['faceRectangle']['left']; You need to use this if you want it as an array $array = json_decode($var, true); Otherwise it will return the json as a ...
-
php返回空的JSON数组(php returns empty JSON array)[2022-05-17]
改变这一点 $town = $POST_['town']; > $query = "Select * From weather WHERE town = '$town'"; 至 $town = $_POST['town']; $query = "Select * From weather WHERE town = '".$town."'"; change this $town = $POST_['town']; > $query = "Select * From weather WHERE ... -
使用$ .ajax [duplicate]在PHP中获取空数组(Getting empty array in PHP while using $.ajax [duplicate])[2023-05-10]
$selected_products = json_decode($_POST['data'], true); echo $selected_products[0]['id']; echo '
'; echo $_POST; echo '
'; var_dump($_POST); 将数据添加到您的帖子 你现在得到null因为那里给出了stringify。 请改变这样的代码。它肯定会起作用。 var data=[{"id":"RECOLOURBALM","option":"Bordeaux"," ... -
如果数组为空,如何从json_encode中排除它?(If array is empty how do I exclude it from json_encode? (PHP))[2024-02-26]
您将希望避免将第二个艺术家添加到随后进行json编码的中间数组中。 $tracks = array(); foreach ($result['tracks'] as $trackdata) { $songId = $trackdata['songId']; $title = $trackdata['title']; $ISRC = $trackdata['ISRC']; $name1 = $trackdata['artists:name[1]' ...