怎样的android到JSON数组转换为字符串数组 [英] android how to convert json array to string array

查看:391
本文介绍了怎样的android到JSON数组转换为字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我获取来自服务器(JSON)的阵列和放大器的表单数据;用我用我的应用程序的指数,如下图所示。

I have an app where I fetch data from server(json) in the form of array & by using the index i used in my app, like below.

JSONObject topobj = new JSONObject(page);
JSONObject innerobj = topobj.getJSONObject("restarutant");
JSONArray phone = innerobj.getJSONArray("phone");
textViewPhone.setText("Phone: " + phone.get(0).toString() + " ,"
                    + phone.get(1).toString());

对于小尺寸阵列我能得到这样的。但是,当阵列包含'n'没有任何元素,并动态我必须用这个的,当时它需要转换成字符串数组。 谁能告诉我怎么转换成JSON数组到字符串数组? 谢谢

for small size array I can get like this. But when array contains 'n' no of elements and dynamically i have to use this, at that time it required to convert into String Array. Can anybody tell me how I convert the json array to String array ? Thank you

推荐答案

<一个href="http://stackoverflow.com/questions/5983932/converting-from-jsonarray-to-string-then-back-again">This应该帮助你。

编辑:

这也许是你所需要的:

ArrayList<String> stringArray = new ArrayList<String>();
JSONArray jsonArray = new JSONArray();
for(int i = 0, count = jsonArray.length(); i< count; i++)
{
    try {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        stringArray.add(jsonObject.toString());
    }
    catch (JSONException e) {
        e.printStackTrace();
    }
}

这篇关于怎样的android到JSON数组转换为字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆