I receive the below JSON and i am able to parse through the Description and date. I have been trying to parse through the time but everything that i try keeps giving me bad output.
The time object is supposed to say 5:30 but i do not know if i am able to parse through that format. I thought it was public String format3339 (boolean allDay)
I have posted the JSON Input, my JSON parsing, and the output.
Input
{"object":[{"description":"blah blah blah","date":"2012-12-11","time":"2000-01-01T05:30:00Z"}]}
Mainly i am worried about "time":"2000-01-01T05:30:00Z"
Parsing
JSONArray arr = null;
list = new ArrayList<HashMap<String, String>>();
}
for (int i = 0; i < arr.length(); i++) {
JSONObject d = arr.getJSONObject(i);
Time time = new Time();
String etime = d.getString(TIME_TAG);
String description = d.getString(DESCRIPTION_TAG);
String date = d.getString(DATE_TAG);
//************************************************************************
//********I suspect that i might be converting the time object incorrectly but whatever
//********i put here either does not work or gives me bad output.
Boolean mtime = time.parse3339(etime);
if (mtime == true) {
etime = time.toString();
}
//************************************************************************
HashMap<String, String> map = new HashMap<String, String>();
map.put(DATE_TAG, date);
map.put(DESCRIPTION_TAG, description);
map.put(TIME_TAG, etime);
list.add(map);
OutPut- I do not understand this output I thought that the input was 3339 format but the output is difficult to work with. I guess i could make a parser to parse out the 530 from the string given but i thought my output would be YYYYMMDDTHHMMSS format from the toString() operation.
20000101T053000UTC(0,0,0,-1,946704600)
EDIT::Here is what i hacked together to get what i want with little effort. It works for now.
JSONArray arr = null;
list = new ArrayList<HashMap<String, String>>();
}
for (int i = 0; i < arr.length(); i++) {
JSONObject d = arr.getJSONObject(i);
String etime = d.getString(TIME_TAG);
String description = d.getString(DESCRIPTION_TAG);
String date = d.getString(DATE_TAG);
if (eTime.charAt(11) == '0')
eTime = eTime.substring(12, 16);
else
eTime = eTime.substring(11, 16);
HashMap<String, String> map = new HashMap<String, String>();
map.put(DATE_TAG, date);
map.put(DESCRIPTION_TAG, description);
map.put(TIME_TAG, etime);
list.add(map);
The best way to solve most Json format problems is to go vise versa: Create your Time, convert to Json Object and investigate String representation. I think you will find your issue quickly.
About your problem:
DateTimeformat you posted is ISO 8601. JSON does not specify this format for dates/times.You can try to use Joda Time to get proper Date type that Json can parse.
Or ISO time format
Or other pretty good way to use
GSONlibrary.