1

我正在尝试使用 net.sf.json.JSONArray 和 net.sf.json.JSONObject 中可用的一些 json 转换方法,但似乎这些对象与(Androids)org.json.JSONArray 和 org.json 不兼容。 JSONObject 对象。本质上,我正在寻找一种将有效的 JSON 字符串转换为 Java 对象(如数组)的有效且简单的方法。net.sf.json 包对象似乎有这样的转换方法。

我的问题是 - net.sf.json.JSONArray 是否与 org.json.JSONArray 兼容,如果可以,如何使用这些对象?试图从一个投射到另一个让我无处可去。

JSONArray jsonArray = new JSONArray();
jsonArray = orgJSONArray; 
jsonArray = (JSONArray)orgJSONArray;

如果我不能将 net.sf.json 与 org.json 对象一起使用,那么在 Android 领域,将有效 JSON 字符串转换为 Java Array 对象的最佳和最有效的方法是什么。

4

1 回答 1

1

By definition net.sf.json.JSONObject is not "compatible" with org.json.JSONObject unless one is a subclass of the other. Even if the two classes were to have word-for-word identical definitions, the different package names would make them totally different and incompatible classes.

于 2012-01-24T01:45:42.873 回答