My json respons contains a CreatedOn Date:
{
"CreatedOn" : "\/Date(1406192939581)\/"
}
I need to convert CreatedOn to a simple date format and count the days of difference from CreatedOn Date to Present Date.
When I debug the below code string CreatedOn showing a null value. How come?
JSONObject store = new JSONObject(response);
if (response.contains("CreatedOn"))
{
String CreatedOn = store.getString("CreatedOn");
}
Best Solution
or
consider using JSON methods instead of contains. JSON has "has()" which validate if key exists.
You should also make sure that you try {} catch {} the String first, to make sure its valid JSON.
Update:
Your Value is /Date(1406192939581)/
which means it must be formatted first. Get it by parsing the string with