Android / Java - JSONException,java.util.HashMap无法转换为JSONObject API< 21

时间:2016-01-16 05:31:57

标签: android json hashmap

我在运行API的设备上遇到了一个非常奇怪的问题< 21。

我有以下JSONObject

{  
   "saturday":"{notes=Walk-Ins Only, open=2016-01-16T08:00:00-05:00, close=2016-01-16T15:00:00-05:00}",
   "wednesday":"{notes=Walk-Ins Only, open=2016-01-20T09:00:00-05:00, close=2016-01-20T18:45:00-05:00}",
   "tuesday":"{notes=Walk-Ins Only, open=2016-01-19T09:00:00-05:00, close=2016-01-19T18:45:00-05:00}",
   "friday":"{notes=Walk-Ins Only, open=2016-01-22T09:00:00-05:00, close=2016-01-22T18:45:00-05:00}",
   "thursday":"{notes=Appointments & Walk-Ins, open=2016-01-21T09:00:00-05:00, close=2016-01-21T18:45:00-05:00}",
   "monday":"{notes=null, open=null, close=null}",
   "sunday":"{notes=null, open=null, close=null}"
}

在尝试获取给定日期的JSONObject时,在运行API> = 21的设备上,我将使用以下示例代码

jsonObject.getJSONObject("tuesday")

但是,在运行API<的设备上成功返回JSONObject。 21同样精确的代码抛出

Value {notes=Walk-Ins Only, open=2016-01-19T09:00:00-05:00, close=2016-01-19T18:45:00-05:00} at tuesday of type java.util.HashMap cannot be converted to JSONObject

为什么会这样?

编辑:我的映射代码并不特别 -

JSONObject loungeHours = new JSONObject(ParseCloud.<Map>callFunction(STORE_HOURS_ENDPOINT, new HashMap<String, Object>()));

使用调试器进行分析时,使用以下

成功填充了loungeHours
{  
   "saturday":"{notes=Walk-Ins Only, open=2016-01-16T08:00:00-05:00, close=2016-01-16T15:00:00-05:00}",
   "wednesday":"{notes=Walk-Ins Only, open=2016-01-20T09:00:00-05:00, close=2016-01-20T18:45:00-05:00}",
   "tuesday":"{notes=Walk-Ins Only, open=2016-01-19T09:00:00-05:00, close=2016-01-19T18:45:00-05:00}",
   "friday":"{notes=Walk-Ins Only, open=2016-01-22T09:00:00-05:00, close=2016-01-22T18:45:00-05:00}",
   "thursday":"{notes=Appointments & Walk-Ins, open=2016-01-21T09:00:00-05:00, close=2016-01-21T18:45:00-05:00}",
   "monday":"{notes=null, open=null, close=null}",
   "sunday":"{notes=null, open=null, close=null}"
}

完整的堆栈跟踪

W/System.err: org.json.JSONException: Value {notes=Walk-Ins Only, open=2016-01-19T09:00:00-05:00, close=2016-01-19T18:45:00-05:00} at tuesday of type java.util.HashMap cannot be converted to JSONObject
W/System.err:     at org.json.JSON.typeMismatch(JSON.java:100)
W/System.err:     at org.json.JSONObject.getJSONObject(JSONObject.java:573)
W/System.err:     at com.hitchtech.adamsbarberlounge.parse.ParseDelegate.getOpenHours(ParseDelegate.java:127)
W/System.err:     at com.hitchtech.adamsbarberlounge.application.main.LoungeDetailFragment$LoungeInfoCardController.populateHours(LoungeDetailFragment.java:247)
W/System.err:     at com.hitchtech.adamsbarberlounge.application.main.LoungeDetailFragment$LoungeInfoCardController.<init>(LoungeDetailFragment.java:105)
W/System.err:     at com.hitchtech.adamsbarberlounge.application.main.LoungeDetailFragment.setupLoungeInfoCardController(LoungeDetailFragment.java:73)
W/System.err:     at com.hitchtech.adamsbarberlounge.application.main.LoungeDetailFragment.onViewCreated(LoungeDetailFragment.java:64)
W/System.err:     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
W/System.err:     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
W/System.err:     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
W/System.err:     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
W/System.err:     at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
W/System.err:     at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:441)
W/System.err:     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
W/System.err:     at android.app.Activity.performResume(Activity.java:5182)
W/System.err:     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2732)
W/System.err:     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
W/System.err:     at android.app.ActivityThread.access$600(ActivityThread.java:141)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err:     at android.os.Looper.loop(Looper.java:137)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5041)
W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err:     at java.lang.reflect.Method.invoke(Method.java:511)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
W/System.err:     at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案