【问题标题】:How can i post this by volley [closed]我怎样才能通过凌空发布这个[关闭]
【发布时间】:2016-11-10 10:58:39
【问题描述】:

“工作日”:[ { “day_id”:2, “来自”:11, “到”:22 }, { “day_id”:3, “来自”:10, “到”:23 } ],

这是我需要发布的脚本的一部分 我正在与 Gson 一起使用凌空抽射有人可以帮忙吗

{
    "userId": 2,
    "token": "bdajkvnbadkvda1ad1fadf4ad5f1da5",
    "name": "Center 123",
    "address": "12 Ramsis Str.,",
    "lat": "30.31194946131",
    "long": "30.31194946131",
    "location": "Assute",
    "phone": "032365653232",
    "owner_name": "Ahmed",
    "owner_number": "164956465464",
    "registry_number": "2161312",
    "taxation_card": "2326-66321",
    "contract_code": "1211132",
    "remark": "Beside phrmacy",
    "working_days": [
       {
          "day_id": 2,
          "from": 11,
          "to": 22
        },
         {
          "day_id": 3,
          "from": 10,
          "to": 23
        }
    ],
    "images": [
      {
       "url": "uploads/center/s51fdf5df1d5.png"
       },
       {
        "url": "uploads/center/s5d1f6d645616.png"
        }
    ]
   }  

【问题讨论】:

  • 发布你到目前为止所做的代码
  • 您是否尝试过本网站上已经存在的任何“解析 json 数据”问题?
  • 我正在投票这个问题,因为它是这个列表的副本stackoverflow.com/search?q=%5Bandroid-volley%5D+parse+json
  • 我投票结束这个问题作为离题,因为它表明没有研究工作。

标签: android


【解决方案1】:

使用 www.jsonschema2pojo.org 创建 Java 对象并使用 Gson 库对其进行解析:http://www.vogella.com/tutorials/JavaLibrary-Gson/article.html

【讨论】:

    【解决方案2】:

    您可以使用 volley 轻松解析您的响应。

    try {
    
              JSONObject jsonObject = new JSONObject(your_response);
              int userId = jsonObject.getInt("userId");
              String token = jsonObject.getString("token");
                                .
                                .
                                .
                                .
    
               JSONArray working_days = jsonObject.getJSONArray("working_days");
    
                for (int i = 0; i < working_days.length(); i++) {
                          int day_id = jsonObject.getInt("day_id");
                          int from = jsonObject.getInt("from");
                          int to = jsonObject.getInt("to");
                }
    
    
              JSONArray images = jsonObject.getJSONArray("images");
    
                for (int i = 0; i < working_days.length(); i++) {
                         int url = jsonObject.getInt("url");
                }
    
           } catch (JSONException e) {
              Log.e(TAG, "Your Boss is Calling");
           }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多