if condition to whether json object has jsonarray or jsonobject
JSONObject json = new JSONObject(jsonString);
if (json.has("data")) {
JSONObject dataObject = json.optJSONObject("data");
if (dataObject != null) {
//Do things with object.
} else {
JSONArray array = json.optJSONArray("data");
//Do things with array
}
} else {
// Do nothing or throw exception if "data" is a mandatory field
}
Also in JavaScript:
- node js http request get parameters
- jquery wrap inner text
- empty string in javascript
- apache log format json
- how to make an image like canvas in node js
- js ajax post strings
- hot to start cypress
- js change text on hover
- jquery get form data
- ctx.fillstyle
- react pass parameter to component
- redirect javascript
- remove character at index from string javascript
- what is .eslint.js in vue
- caesar cipher javascript code
- if button is keeping pressed execute increment javascript
- comment jsx code
- filesaver.min.js cdn
- flutter reorder map by key
- variables in js
- switch statement in javascript
- js date methods
- javascript round up
- js convert truthy