有个问题是json格式是嵌套的,传输的时候值每次都发送不到服务器。
比如:json格式是:{
"title":"555","type":"record","language":"zh-hans","uid":"1","status":"1","body":"数据","field_record_ftate":[{"value":{"date":"2010-01-27"}}],"field_record_state":[{"value":{"date":"2010-01-27"}}]
}上面是服务器的格式。但现在在手机上需要按上面格式发送给服务器
,问题是时间(field_record_ftate)参数不知道该怎么传给服务器。
有没有遇到这个问题的朋友?
比如:json格式是:{
"title":"555","type":"record","language":"zh-hans","uid":"1","status":"1","body":"数据","field_record_ftate":[{"value":{"date":"2010-01-27"}}],"field_record_state":[{"value":{"date":"2010-01-27"}}]
}上面是服务器的格式。但现在在手机上需要按上面格式发送给服务器
,问题是时间(field_record_ftate)参数不知道该怎么传给服务器。
有没有遇到这个问题的朋友?
或者:其他的可以是字符串类型,最后两个是数组类型,然后通过这些指定了类型的数据组成一个json传过去。
然后把JSON字符串POST给服务器。
关于转换JSON格式请参考:
http://www.cnblogs.com/xwdreamer/archive/2011/12/16/2296904.html
public static void demo() {
String jsonstr = "{\"info\":[{\"name\":\"123\",\"xy\":111},{\"name\":\"123\",\"xy\":111},{\"name\":\"123\",\"xy\":111}]}";
JSONObject obj;
try {
obj = new JSONObject(jsonstr);
JSONArray array = obj.getJSONArray("info");
for (int i = 0; i < array.length(); i++) {
JSONObject item = (JSONObject) array.get(i);
System.out.println(item.getString("name") + "_________"
+ item.getString("xy"));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
发给服务器用HTTP POST 就可以。