mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
fixing stleary/JSON-Java#233
This commit is contained in:
parent
c044eb14dd
commit
56be31e7a8
2 changed files with 34 additions and 0 deletions
|
@ -964,6 +964,23 @@ public class JSONArray implements Iterable<Object> {
|
||||||
return new JSONPointer(jsonPointer).queryFrom(this);
|
return new JSONPointer(jsonPointer).queryFrom(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries and returns a value from this object using {@code jsonPointer}, or
|
||||||
|
* returns null if the query fails due to a missing key.
|
||||||
|
*
|
||||||
|
* @param jsonPointer the string representation of the JSON pointer
|
||||||
|
* @return the queried value or {@code null}
|
||||||
|
* @throws IllegalArgumentException if {@code jsonPointer} has invalid syntax
|
||||||
|
*/
|
||||||
|
public Object optQuery(String jsonPointer) {
|
||||||
|
JSONPointer pointer = new JSONPointer(jsonPointer);
|
||||||
|
try {
|
||||||
|
return pointer.queryFrom(this);
|
||||||
|
} catch (JSONPointerException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an index and close the hole.
|
* Remove an index and close the hole.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1342,6 +1342,23 @@ public class JSONObject {
|
||||||
return new JSONPointer(jsonPointer).queryFrom(this);
|
return new JSONPointer(jsonPointer).queryFrom(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries and returns a value from this object using {@code jsonPointer}, or
|
||||||
|
* returns null if the query fails due to a missing key.
|
||||||
|
*
|
||||||
|
* @param jsonPointer the string representation of the JSON pointer
|
||||||
|
* @return the queried value or {@code null}
|
||||||
|
* @throws IllegalArgumentException if {@code jsonPointer} has invalid syntax
|
||||||
|
*/
|
||||||
|
public Object optQuery(String jsonPointer) {
|
||||||
|
JSONPointer pointer = new JSONPointer(jsonPointer);
|
||||||
|
try {
|
||||||
|
return pointer.queryFrom(this);
|
||||||
|
} catch (JSONPointerException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a string in double quotes with backslash sequences in all the
|
* Produce a string in double quotes with backslash sequences in all the
|
||||||
* right places. A backslash will be inserted within </, producing <\/,
|
* right places. A backslash will be inserted within </, producing <\/,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue