java - Problems in JSON results calling JAWBONE API -
i'm developing android app analyze band data. using example given in sdk android , @ moment can trend data json object. problem json object malformed. in fact when try deserialize trend data with:
jsonelement je = new jsonparser().parse(o.tostring());
i following error:
com.google.gson.jsonsyntaxexception: com.google.gson.stream.malformedjsonexception: expected value @ line ...
moreover, inspecting result of api call get:
{meta={user_xid=masked, message=ok, code=200.0, time=1.430319261e9}, data={earliest=2.0130408e7, data=[[2.0150423e7, {e_protein=null, weight=78.0, goal_body_weight_intent=null, body_fat=null, m_distance=8073.0, s_awakenings=null, height=1.72, m_lcat=1336.0, goal_body_weight=null, s_quality=null, m_steps=10760.0, e_cholesterol=null, s_light=null, e_sat_fat=null, n_bedtime=null, m_workout_time=0.0, e_calcium=null, s_bedtime=null, n_awakenings=null, n_light=null, s_awake_time=null, pal=null, n_duration=null, m_lcit=9660.0, m_active_time=5717.0, e_unsat_fat=null, m_calories=532.710151311, e_calories=null, bmr=1426.58256449, m_total_calories=1959.2927158, n_sound=null, e_sugar=null, e_sodium=null, s_awake=null, s_asleep_time=null, s_duration=null, n_awake=null, age=69.8273972603, e_carbs=null, e_fiber=null, s_sound=null, n_quality=null, n_awake_time=null, gender=0.0, n_asleep_time=null}], [2.0150424e7, {e_protein=null, weight=78.0, goal_body_weight_intent=null, body_fat=null, m_distance=9641.0, s_awakenings=null, height=1.72, m_lcat=1145.0, goal_body_weight=null, s_quality=null, m_steps=12657.0, e_cholesterol=null, s_light=null, e_sat_fat=null, n_bedtime=null, m_workout_time=0.0, e_calcium=null, s_bedtime=null, n_awakenings=null, n_light=null, s_awake_time=null, pal=null, n_duration=null, m_lcit=11460.0, m_active_time=6508.0, e_unsat_fat=null, m_calories=632.988689047, e_calories=null, bmr=1412.57952142, m_total_calories=2045.56821047, n_sound=null, e_sugar=null, e_sodium=null, s_awake=null, s_asleep_time=null, s_duration=null, n_awake=null, age=69.8301369863, e_carbs=null, e_fiber=null, s_sound=null, n_quality=null, n_awake_time=null, gender=0.0, n_asleep_time=null}], [2.0150425e7, {e_protein=null, weight=78.0, goal_body_weight_intent=null, body_fat=null, m_distance=21643.0, s_awakenings=null, height=1.72, m_lcat=2455.0, goal_body_weight=null, s_quality=null, e_calories=null, e_cholesterol=null, s_light=null, e_sat_fat=null, n_bedtime=null, m_workout_time=0.0, e_calcium=null, s_bedtime=null, n_awakenings=null, n_light=null, s_awake_time=null, s_sound=null, pal=null, n_duration=null, m_lcit=1860.0, m_active_time=14625.0, e_unsat_fat=null, m_calories=1422.11015205, bmr=1269.04654879, m_total_calories=2691.15670084, n_sound=null, s_asleep_time=null, e_sodium=null, s_awake=null, e_sugar=null, s_duration=null, n_awake=null, age=69.8328767123, e_carbs=null, e_fiber=null, m_steps=28322.0, n_quality=null, n_awake_time=null, gender=0.0, n_asleep_time=null}], [2.0150426e7, {e_protein=null, weight=78.0, goal_body_weight_intent=null, body_fat=null, m_distance=1572.0, s_awakenings=null, height=1.72, m_lcat=265.0, goal_body_weight=null, s_quality=null, m_steps=2116.0, e_cholesterol=null, s_light=null, e_sat_fat=null, n_bedtime=null, m_workout_time=0.0, e_calcium=null, s_bedtime=null, n_awakenings=null, n_light=null, e_calories=null, pal=null, n_duration=null, m_lcit=6360.0, s_awake_time=null, e_unsat_fat=null, m_calories=104.843981181, bmr=1507.45521348, m_total_calories=1612.29919466, n_sound=null, s_asleep_time=null, e_sodium=null, s_awake=null, e_sugar=null, s_duration=null, n_awake=null, age=69.8356164384, e_carbs=null, e_fiber=null, s_sound=null, n_quality=null, n_awake_time=null, gender=0.0, n_asleep_time=null, m_active_time=1140.0}], [2.0150427e7, {e_protein=null, weight=78.0, goal_body_weight_intent=null, body_fat=null, m_distance=4334.0, s_awakenings=0.0, height=1.72, m_lcat=1091.0, goal_body_weight=null, s_quality=0.0, m_steps=5726.0, e_cholesterol=null, s_light=0.0, e_sat_fat=null, n_bedtime=null, m_workout_time=0.0, e_calcium=null, s_bedtime=-5400.0, n_awakenings=null, n_light=null, s_awake_time=17100.0, pal=null, n_duration=null, m_lcit=4320.0, m_active_time=2978.0, e_unsat_fat=null, m_calories=283.00944155, e_calories=null, bmr=1474.94024527, m_total_calories=1757.94968682, n_sound=null, s_asleep_time=-5400.0, e_sodium=null, s_awake=0.0, e_sugar=null, s_duration=22500.0, n_awake=null, age=69.8383561644, e_carbs=null, e_fiber=null, s_sound=0.0, n_quality=null, n_awake_time=null, gender=0.0, n_asleep_time=null}], [2.0150428e7, {e_protein=null, weight=78.0, goal_body_weight_intent=null, body_fat=null, m_distance=null, s_awakenings=null, height=1.72, m_lcat=null, goal_body_weight=null, s_quality=null, e_calories=null, e_cholesterol=null, s_light=null, e_sat_fat=null, n_bedtime=null, m_workout_time=null, e_calcium=null, s_bedtime=null, n_awakenings=null, n_light=null, m_steps=null, pal=null, n_duration=null, m_lcit=null, s_awake_time=null, e_unsat_fat=null, m_calories=null, bmr=1527.57418082, m_total_calories=1527.57418082, n_sound=null, s_asleep_time=null, e_sodium=null, s_awake=null, e_sugar=null, s_duration=null, n_awake=null, age=69.8410958904, e_carbs=null, e_fiber=null, s_sound=null, n_quality=null, n_awake_time=null, gender=0.0, n_asleep_time=null, m_active_time=null}], [2.0150429e7, {e_protein=null, weight=78.0, goal_body_weight_intent=null, body_fat=null, m_distance=null, s_awakenings=null, height=1.72, m_lcat=null, goal_body_weight=null, s_quality=null, m_steps=null, e_cholesterol=null, s_light=null, e_sat_fat=null, n_bedtime=null, m_workout_time=null, e_calcium=null, s_bedtime=null, n_awakenings=null, n_light=null, s_awake_time=null, pal=null, n_duration=null, m_lcit=null, m_active_time=null, e_unsat_fat=null, m_calories=null, e_calories=null, bmr=1527.55567397, m_total_calories=503.191690242, n_sound=null, s_asleep_time=null, e_sodium=null, s_awake=null, e_sugar=null, s_duration=null, gender=0.0, age=69.8438356164, e_carbs=null, e_fiber=null, s_sound=null, n_quality=null, n_awake_time=null, n_awake=null, n_asleep_time=null}]], links={next=/nudge/api/v.1.1/users/ymqeh-uuau8hs54ad7mxjw/trends/?end_date=20150422&bucket_size=d&num_buckets=7}}}
the main problem in previous json object keys aren't formed. in fact should strings of characters between "". please give me indication on how solve problem? lot help. [edit]
this callback function starting modify data jawbone:
private callback genericcallbacklistener = new callback<object>() { @override public void success(object o, response response) { log.e(log_tag, "api call successful, json output: " + o.tostring()); //i added following 3 lines of code parse json result jsonelement je = new jsonparser().parse(o.tostring()); jsonobject root = je.getasjsonobject(); jsonelement je2 = root.get("data"); toast.maketext(getapplicationcontext(), je2.tostring(), toast.length_long).show(); } @override public void failure(retrofiterror retrofiterror) { log.e(log_tag, "api call failed, error message: " + retrofiterror.getmessage()); toast.maketext(getapplicationcontext(), retrofiterror.getmessage(), toast.length_long).show(); }
};
ok believe know problem is. using retrofit callback
wrong.
you not need parse result. jawbone + retrofit you.
check example:
public interface bookservice{ @get("/books") void getbooks(callback<list<book>> books); } // , private callback genericcallbacklistener = new callback<list<book>>() { @override public void success(list<book> books, response response) { [...] // use books } @override public void failure(retrofiterror retrofiterror) { } } taskservice.getbooks(genericcallbacklistener);
so not try manually parse response. let jawbone android sdk you.
Comments
Post a Comment