你必须在服务器端编写一个web服务。可以将数据作为Json数据包发送到设备,并在设备中解析json数据包并访问数据。你对Web服务调用应该是一个HTTP调用如
的http:\服务器\方法An Iteraitve \ get_somedata名=东西
和服务器应该在数据库中查询此参数并发送给您的效应初探为JSON。 解析json并获取您的详细信息。
编辑: 在服务器响应头中设置内容类型为“application/json”。这是客户端向服务器发送http post请求的一个例子。这里jsonobjSend是json我已经构建发送到服务器的一些细节。 ex {table:“sometable”,id:90}。 jsonobjRecv是将服务器
HttpPost httpPostRequest = new HttpPost(url);
StringEntity se;
se = new StringEntity(jsonObjSend.toString());
// Set HTTP parameters
httpPostRequest.setEntity(se);
httpPostRequest.setHeader("Authorization", usercredential);
httpPostRequest.setHeader("Accept", "application/json");
httpPostRequest.setHeader("Content-type", "application/json");
httpPostRequest.setHeader("Accept-Encoding", "gzip"); // only set this parameter if you would like to use gzip compression
long t = System.currentTimeMillis();
response = (HttpResponse) httpclient.execute(httpPostRequest);
Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis()-t) + "ms]");
//Get hold of the response entity (-> the data):
HttpEntity entity = response.getEntity();
if (entity != null) {
// Read the content stream
InputStream instream = entity.getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
instream = new GZIPInputStream(instream);
}
// convert content stream to a String
String resultString= convertStreamToString(instream);
Log.v(null, "resultString "+resultString);
instream.close();
// Transform the String into a JSONObject
if(resultString!=null){
jsonObjRecv = new JSONObject(resultString);
}
// Raw DEBUG output of our received JSON object:
Log.i(TAG,"<jsonobject>\n"+jsonObjRecv.toString()+"\n</jsonobject>");
return jsonObjRecv;
}
创建/分析JSON检查json.org所
如何确保我在C#中的web服务实际上以JSON格式发送数据? – Dazzmaster1 2011-12-28 07:17:54