JSON解析Android中JSON、Android

2023-09-11 12:31:12 作者:用一生守护①个约定。

我已经搜索了很多关于JSON解析在Android中,但不能完全信服。其实有一个简单的想法,但还不是特别清楚有关JSON解析。

I have searched alot on JSON Parsing in Android, but couldn't quite convinced. Actually got a brief idea but not so clear yet regarding JSON Parsing.

如何实现的JSON解析在应用程序?

How to implement the JSON Parsing in the Application?

推荐答案

这是一个非常简单的JSON字符串

This is a very simple JSON String

{"key1":"value1","key2":"value2"}

为了得到它的值使用的JSONObject 是这样的:

In order to get values for it use JSONObject like this :

JSONObject json_obj=new JSONObject(your json string);
String value1=json_obj.getString("key1");
String value2=json_obj.getString("key2");

这是一个稍微复杂的JSON字符串

This is a slightly complex json string

[{"key1":"value1","key2":"value2"},{"key1":"value1","key2":"value2"}]

为了从这种使用提取值 JSONArray

In order to extract values from this use JSONArray

JSONArray jArray=new JSONArray(your json string);
for(int i=0;i<(jArray.length());i++)
{
    JSONObject json_obj=jArray.getJSONObject(i);
    String value1=json_obj.getString("key1");
    String value2=json_obj.getString("key2");
}

希望这有助于有点...........

Hope this helps a bit...........