如何将JSON对象转换为类对象 [英] how to convert json object into class object
问题描述
如何转换这个JSON clsError和用户id值
How to convert this json clsError and userId values
字符串TEMP ={clsError:{错误code:110,ErrorDescription中:要求增加},用户名:36}
和它们作为参数传递
clsError errorObject =新clsError(用户ID,clsError);
推荐答案
第一次使用这样的:<一href=\"http://developer.android.com/reference/org/json/JSONObject.html#JSONObject%28java.lang.String%29\" rel=\"nofollow\">http://developer.android.com/reference/org/json/JSONObject.html#JSONObject(java.lang.String)
JSONObject tempJson = new JSONObject(temp);
JSONObject clsErrorJson = tempJson.getJSONObject("clsError");
clsError errorObject = new clsError(tempJson.getString("UserID"),
clsErrorJson.getInt("clsError") + ": "
+ clsErrorJson.getString("ErrorDescription"));
这基本上是它。但我不知道的clsError构造函数的第二个参数。我只是认为这是在我的例子字符串:),但是这应该给你的想法如何做到这一点。你将有环绕与try / catch语句。月食将告诉你如何:)
that is basically it. but i was not sure about the second parameter of the clsError constructor. i just assumed it is a string in my example :) but this should give you the idea how to do this. and you will have to surround that with try/catch. eclipse will tell you how :)
这篇关于如何将JSON对象转换为类对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!