Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: find longest word in a string javascript 
Javascript :: define conastant js 
Javascript :: javascript Modules Always use Strict Mode 
Javascript :: Check if a number is even or odd 
Javascript :: relation between leaves nodes and internal nodes in binary tree 
Javascript :: how to defined an array in js 
Javascript :: javascript looop 
Javascript :: url 
Javascript :: Material-ui alarm icon 
Javascript :: read more/less button with smoth expand 
Javascript :: node js find directory change directory 
Python :: import keys selenium 
Python :: python get appdata path 
Python :: python update pip3 
Python :: pandas save file to pickle 
Python :: error tokenizing data. c error 
Python :: python exception with line number 
Python :: python open web browser 
Python :: how to get the calendar of current month in python 
Python :: python clear console 
Python :: sorting by column in pandas 
Python :: colab im show 
Python :: Cannot mask with non-boolean array containing NA / NaN values 
Python :: gdscript string format 
Python :: sort by index 2d array python 
Python :: pyaudio not installing ubuntu 
Python :: check python version mac 
Python :: python check file extension 
Python :: python reimport module after change 
Python :: pyspark date to week number 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =