2014-10-07 60 views
2

我目前正在開發一個顯示JSON序列化對象的Android應用程序。 它適用於我的Nexus 5(4.4.2),但在Samsung Galaxy S3(4.3)上崩潰。該應用程序崩潰,因爲此設備上特別發生JSONException。getJSONObject在android 4.3下拋出JSONException但在Android 4.4.2上正常工作

我的JSON從地圖生成的,就像這樣:

Map<String, Object> dataMap = new HashMap<String, Object>(); 
// 
// filling the map 
// 
new JSONObject(map); 

日誌:

Caused by: org.json.JSONException: Value {dealer={logo=null, name=Au café Bonheur}, title=Un mocha à 3€, price=3.0, feed_picture=https://shotgun-staging.s3.amazonaws.com/deals/tutorial1/feed, original_price=5.0} at deal of type java.lang.String cannot be converted to JSONObject 
      at org.json.JSON.typeMismatch(JSON.java:100) 
      at org.json.JSONObject.getJSONObject(JSONObject.java:577) 
      at com.shotguntheapp.android.adapters.StackAdapter.getView(StackAdapter.java:33) 
            at com.shotguntheapp.android.views.StackView.computeLayout(StackView.java:74) 
            at com.shotguntheapp.android.views.StackView.setAdapter(StackView.java:60) 
            at com.shotguntheapp.android.activities.FeedActivity.displayFeed(FeedActivity.java:91) 
            at com.shotguntheapp.android.activities.Tuto1FeedActivity.reload(Tuto1FeedActivity.java:97) 
            at com.shotguntheapp.android.activities.RequestsActivity.onResume(RequestsActivity.java:62) 
            at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1209) 
            at android.app.Activity.performResume(Activity.java:5450) 
            at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2909) 
            at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2948) 
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2354) 

的JSON並不似乎是錯誤的。 行引發的異常:

JSONObject deal = shotgun.getJSONObject(Api.JSON_DEAL); 

我沒有發現有同樣的問題其他人,所以我不知道該怎樣發生這種情況的想法。

謝謝你的幫助。

+1

你肯定對這個問題仍然存在只有API的變化? – Brendon 2014-10-07 10:14:33

+0

這個JSON似乎不正確。使用http://json.parser.online.fr/檢查它是否有效。 – 2014-10-07 10:15:55

+0

本網站基於基本的JSON語法。實際上,我使用java映射從無到有生成json。 JSON如何正確與我的聯繫5和錯誤在我的GS3? – 2014-10-07 12:37:47

回答

2

事實上,這個問題是在語法(這是正確的,但不能處處工作)

創建從地圖對象產生一種特殊的JSON語法不上的API低於19工作這就是爲什麼我的應用程序在4.3下崩潰。

已經從地圖的正確的語法,我用這個藉口:

parseFeedData(new JSONObject(new Gson().toJson(object)); 
+0

你能否提供任何鏈接到源代碼? – 2016-03-10 19:13:46

相關問題