服务器端:
Person person = new Person( , ,);
JSONObject obj = new JSONObject();
obj.put("person", person);
Android 客户端:
JSONObject jsonObject = new JSONObject(jsonString);
JSONObject personObje...
分类:
Web程序 时间:
2014-05-26 03:45:00
阅读次数:
260
1.从Object到String要先用Object对象构造一个JSONObject或者JSONArray对象,然后调用它的toString()方法即可(1)示例一1
Book book=new Book();2 book.setName("Java");3 book.setPrice(52.3f);...
分类:
Web程序 时间:
2014-05-24 14:01:02
阅读次数:
355
JSONArray jsonArr =
JSONArray.toJSONObject("数组/集合"); JSONObject obj =
JSONObject.fromObject("对象");所需的jar
包有:json-lib-2.1.jarjson_simple.jarcommons-l.....
分类:
Web程序 时间:
2014-05-24 01:16:25
阅读次数:
250
MainActivity如下:
package cc.cn;
import java.util.HashMap;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import com.android.volley....
分类:
移动开发 时间:
2014-05-18 15:18:31
阅读次数:
297
publicstaticStringcreateJsonString(Stringkey,Objectvalue){
JSONObjectjsonObject=newJSONObject();
jsonObject.put(key,value);
returnjsonObject.toString();
}
分类:
Web程序 时间:
2014-05-13 04:28:35
阅读次数:
316
在json对象和java对象转换时
String s = "{'name':'name1','pwd':'pwd1'}";
Person p = (Person)JSONObject.toBean(JSONObject.fromObject(s), Person.class);
System.out.println(p.getPwd());
上面代码中出现以下异常:
net.sf.json.JSONException: java.lang.NoSuchMethodException...
分类:
编程语言 时间:
2014-05-04 09:05:16
阅读次数:
1650
用android 通过http协议提交数据至服务器 content的内容代码如下:private
static JSONObject connUpload(String baseUrl, Map params, String content) throws
IOException, JSONExce...
分类:
其他好文 时间:
2014-04-30 14:06:47
阅读次数:
490
list集合转换JSON出错误意思是:对象”是一个数组。使用jsonarray代替。解决方法:将JSONObject替换为JSONArray代码:JsonConfig jsonConfig = new JsonConfig();jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);JSONArray json = ...
分类:
Web程序 时间:
2014-04-29 13:43:21
阅读次数:
1280
JsonTools
package com.example.weather_json.tools;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import co...
分类:
Web程序 时间:
2014-04-29 13:37:21
阅读次数:
1039
在使用JSONObject.fromObject的时候,出现“There is a cycle in the hierarchy”异常。意思是出现了死循环,也就是Model之间有循环包含关系;解决办法:使用setCycleDetectionStrategy防止自包含代码:JsonConfig jsonConfig = new JsonConfig();jsonConfig.setCycleDete...
分类:
其他好文 时间:
2014-04-29 13:32:21
阅读次数:
346