【问题标题】:send json data without key发送没有密钥的json数据
【发布时间】:2014-10-08 11:03:55
【问题描述】:

大家好,我想在 android 中发送没有密钥的 json 数据。我已成功发布带有密钥 val 对的 json 数据。但无法在没有密钥的情况下发布 json 数据。任何建议将不胜感激。提前致谢。

对于我使用的密钥 val。

// 1. create HttpClient
HttpClient httpclient = new DefaultHttpClient();

// 2. make POST request to the given URL
HttpPost httpPost = new HttpPost(url);

String json = "";

// 3. build jsonObject
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("mobNo",storedMobNo );



// 4. convert JSONObject to JSON to String
json = jsonObject.toString();



// 5. set json to StringEntity
StringEntity se = new StringEntity(json);

// 6. set httpPost Entity
httpPost.setEntity(se);

// 7. Set some headers to inform server about the type of the
// content
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");

// 8. Execute POST request to the given URL
HttpResponse httpResponse = httpclient.execute(httpPost);

// 9. receive response as inputStream
inputStream = httpResponse.getEntity().getContent();

在上面的代码中,我将“mobNo”作为键传递,并将 storedMobNo 作为值传递。但是现在我只想传递 storedMobNo 而不是键。如何做到这一点?

【问题讨论】:

  • 以字符串或数组形式发送
  • storedMobNo 包含什么?
  • storedMobNo 是一个字符串
  • 好的,谢谢大家,将它作为字符串传递后解决了我的问题。谢谢 Remees M Syde

标签: android json


【解决方案1】:

试试这种json数据:

{
    "column": ["mobno"],
    "data": [
        "123",
        "456",
        "789"
    ]
}

【讨论】:

    猜你喜欢
    • 2020-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-16
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多