android的JSONArray

android的JSONArray,android,json,android-json,Android,Json,Android Json,我有一个程序可以解析JSONArray,但前提是JSONArray中有jsonobject,例如: "weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}] 我试图解析一个jsonarray,如下所示: "messages":["This is a demo message. Enjoy!","Another demonstration message stored in JSON fo

我有一个程序可以解析JSONArray,但前提是JSONArray中有jsonobject,例如:

"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}]
我试图解析一个jsonarray,如下所示:

"messages":["This is a demo message.  Enjoy!","Another demonstration message stored in JSON format.","JSON stands for JavaScript Object Notation (I think)","hello"]
所以我想知道的是,我将如何转换我现在拥有的代码,以便能够解析这种json数组。以下是我当前解析jsonarray的代码:

 @Override
    protected Boolean doInBackground(String... urls) {
        try {

            //------------------>>
            HttpGet httppost = new HttpGet(urls[0]);
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response = httpclient.execute(httppost);

            // StatusLine stat = response.getStatusLine();
            int status = response.getStatusLine().getStatusCode();

            if (status == 200) {
                HttpEntity entity = response.getEntity();
                String data = EntityUtils.toString(entity);


                JSONObject jsono = new JSONObject(data);
                JSONArray jarray = jsono.getJSONArray(/*"actors"*/"weather");


                for (int i = 0; i < jarray.length(); i++) {
                    JSONObject object = jarray.getJSONObject(i);

                    Actors actor = new Actors();

                    actor.setName(object.getString("id"));


                    actorsList.add(actor);

                }
@覆盖
受保护的布尔doInBackground(字符串…URL){
试一试{
//------------------>>
HttpGet-httppost=新的HttpGet(URL[0]);
HttpClient HttpClient=新的DefaultHttpClient();
HttpResponse response=httpclient.execute(httppost);
//StatusLine stat=response.getStatusLine();
int status=response.getStatusLine().getStatusCode();
如果(状态==200){
HttpEntity=response.getEntity();
字符串数据=EntityUtils.toString(实体);
JSONObject jsono=新的JSONObject(数据);
JSONArray jarray=jsono.getJSONArray(/*“actors”*/“weather”);
for(int i=0;i
如果您需要查看更多我的代码,请询问,我很乐意提供。谢谢。

您可以这样做:

if (status == 200)
    {
        HttpEntity entity = response.getEntity();
        String data = EntityUtils.toString(entity);

        JSONObject jsono = new JSONObject(data);
        JSONArray jarray = jsono.getJSONArray("messages");
        for (int i = 0; i < jarray.length(); i++)
        {
            String message = jarray.getString(i);
        }
    }
if(状态==200)
{
HttpEntity=response.getEntity();
字符串数据=EntityUtils.toString(实体);
JSONObject jsono=新的JSONObject(数据);
JSONArray jarray=jsono.getJSONArray(“消息”);
for(int i=0;i
在我看来,这似乎不符合JSON标准,如果你登录此网站,你会注意到:我非常感谢!我不想再打扰你了,但你知道如何更新此内容吗?我会使用刷新按钮或其他什么吗?抱歉,但我不明白。你到底想更新什么以及在哪里更新?比如说,JSON中添加了一个新项目数组如何在应用程序上单击刷新按钮或其他内容,新项目将添加到我的列表中。您应该刷新适配器:adapter.notifyDataSetChanged();