Reputation: 19
I received a JSON field from mondb:
"publishDate": NumberLong("1500948351000"),
I try to parse it as this in Java:
String docTime = new DateTime(jsonDoc.getLong(publishDate)).toString();
But receive an exception:
org.json.JSONException: JSONObject["publishDate"] is not a long.
How to retrieve the datetime from the NumberLong?
Upvotes: 0
Views: 318
Reputation: 3346
'NumberLong("1500948351000")' is not a long.
String aa = jsonDoc.getString(publishDate)
is probably the String with value NumberLong("1500948351000"). And then you can use
String longString = aa.subString(aa.indexOf("\"") + 1, aa.lastIndexOf("\""));
long pbDate = Long.parseLong(longString);
to obtain the long value.
Upvotes: 1