私はJavaとAndroidが初めてなので、ご容赦ください。wcf サービスを呼び出し、返された結果を JSON から Java オブジェクトに変換する関数を作成しようとしています (型を object として渡しますt
) が、 で null ポインター例外をスローしていますt
。null
正しい型のオブジェクトを渡して、変換時に満たされるようにします。親切に私を助けてください。
public static String Post(String serviceURL, Map<String, String> entites,
Class<?> t) {
String responseString = "";
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Gson gson = new GsonBuilder().create();
//now we will try to convert the class to the specified type.
t = (Class<?>) gson.fromJson(responseString, t);
} catch (Exception e) {
responseString = e.toString();
}
return responseString;
どうもありがとう。
何度か試行した後、このコードになりましたが、まだヌル ポインター例外に直面しています。
MemberInfo mem = new MemberInfo();
TypeToken<MemberInfo> m = null ;
ServiceCaller.Post(getString(R.string.LoginService), values , m);
Gson gson = new GsonBuilder().create();
//now we will try to convert the class to the specified type.
t = (TypeToken<T>) gson.fromJson(responseString, (Type) t);