我正在使用Gson類將JSON字符串數據轉換爲Intent
對象。但我得到例外。意向將意圖的JSON字符串轉換爲意圖對象的例外
JSON字符串:
{
"targetIntent":{
"mAction":"android.intent.action.VIEW",
"mData":{
"authority":{
"decoded":"com.android.contacts",
"encoded":"com.android.contacts"
},
"fragment":{
},
"path":{
"decoded":"NOT CACHED",
"encoded":"/contacts/lookup/1471i541ce89b89ad6a59"
},
"query":{
},
"scheme":"content",
"uriString":"NOT CACHED",
"host":"NOT CACHED",
"port":-2
},
"mFlags":0
}
}
轉換代碼:
Intent targetIntent =
gson.fromJson(histroyDataObject.getString("targetIntent"), Intent.class);
這給了異常:
Cause: Instantiation Exception
Detail Message: Failed to invoke private android.net.Uri() with no args
堆棧跟蹤:
08-31 01:08:19.045: W/System.err(290): Caused by: java.lang.InstantiationException: android.net.Uri
08-31 01:08:19.065: W/System.err(290): at java.lang.reflect.Constructor.constructNative(Native Method)
08-31 01:08:19.065: W/System.err(290): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
08-31 01:08:19.065: W/System.err(290): at com.google.gson.internal.ConstructorConstructor$2.construct(ConstructorConstructor.java:91)
08-31 01:08:19.076: W/System.err(290): ... 24 more
感謝您的幫助。
的「JSON字符串」是一個爛攤子,不是一個有效的JSON字符串... – Xaerxess
對不起我的錯誤錯字:(現在編輯 –
儘管如此,'{「權威」: 「decode」:「com.android.contacts」,「encoded」'不是有效的JSON片段,JSON對象也應該以'{'開始。將JSON字符串粘貼到[this validator]中(http://jsonformatter.curiousconcept你可以看到你有錯誤 – Xaerxess