大家好我想在没有android的情况下发送json数据。我已成功发布带有密钥对的json数据。但无法在没有密钥的情况下发布json数据。任何建议将不胜感激。提前谢谢。
对于我使用过的关键值。
// 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而不是密钥。怎么做?
答案 0 :(得分:0)
嗨,尝试这种json数据
{
"column": ["mobno"],
"data": [
"123",
"456",
"789"
]
}
我希望这对您有帮助。