2015-07-22 61 views
-2

我在将包转换为JSON时遇到了问题。这里是我的代码:Java Android:如何将意图数据解析为JSOn格式?

Bundle extras = intent.getExtras(); 
JSONObject object_example = new JSONObject(extras.getString("data")); 
String message = object_example.getString("alert"); 

,当我试图用离子编译,我得到以下错误:

Users/Lukasz/xxxx/platforms/android/src/com/plugin/gcm/GCMIntentService.java:73: error: unreported exception JSONException; must be caught or declared to be thrown 
     JSONObject object_example = new JSONObject(extras.getString("data")); 
            ^
/Users/Lukasz/xxxx/platforms/android/src/com/plugin/gcm/GCMIntentService.java:74: error: unreported exception JSONException; must be caught or declared to be thrown 
     String message = object_example.getString("alert"); 
               ^

什么我做错了:)?

谢谢!

+0

记录你的完整JSON,理解它然后尝试解析,或张贴在你的问题 –

+0

也许使用try catch块来捕捉JSONException – Chol

回答

1

我认为方法应在认定中扔JsonException或必须使用try catch赶上JsonException如果你想使用JSONObject。但是直到你发布完整的日志和你的代码,它仍然不清楚。

+0

是的,我只是这样做,它的工作:) – uksz