不完整的文件Json

时间:2017-02-18 11:09:38

标签: android json android-volley

为什么当我添加一个组件的列表时不是“[]”?

 try {
            json.accumulate("name_channel", txt_channel.getText().toString());
            json.accumulate("channel_date", new Date().toString());
            JSONArray jsonArray = new JSONArray();
            JSONObject idJSON = new JSONObject();
            idJSON.accumulate("id",MainActivity.id_user);
            json.accumulate("list_users", idJSON);
        } catch (JSONException e) {
            e.printStackTrace();
        }

它生成以下内容:

{"name_channel":"xxx","channel_date":"Sat Feb 18 12:00:27 GMT+01:00 2017","list_users":{"id":"1445353654356"}}

但我需要:与[]

{"name_channel":"xxx","channel_date":"Sat Feb 18 12:00:27 GMT+01:00 2017","list_users":[{"id":"1445353654356"}]}

1 个答案:

答案 0 :(得分:2)

要做到这一点,你需要做这样的事情

@section Login{

    @if (Session["UserID"] == null)
    {
        <li><a href="/Home/Login"><span class="glyphicon glyphicon-log-in"> </span> &nbsp Log In</a></li>
        <li><a href="/Home/Register"><span class="glyphicon glyphicon-plus"> </span> Create an Account</a></li>
    }
    else
    {    
        int userID = (int)Session["UserID"];
        <li><a href="/Home/UserDetail/@userID"><span class="glyphicon glyphicon-user"> </span> User Detail</a></li>
        <li><a href="/Home/Orders"><span class="glyphicon glyphicon-gift"> </span> &nbsp Orders</a></li>
        <li><a href="/Home/LogOut"><span class="glyphicon glyphicon-log-out"> </span> &nbsp Log Out</a></li>
    }
}