1. java怎麼把對象序列化成.json文件
首先引用json 對應的jar包
1.commons-lang.jar
2.commons-beanutils.jar
3.commons-collections.jar
4.commons-logging.jar
5.ezmorph.jar
6.json-lib-2.2.2-jdk15.jar
實現方法就是 JSONObjectjson = JSONObject.fromObject(map);
2. 怎麼用java編寫json文件
先生成map 然後用alibaba的fastjson,附件中的這個包,里頭有你意想不到的API
例如:
Map map = ......;
map的結構和要生成的字元串結構一致就行,你的optionset在map里頭的結構就是一個list
list optionset= new ArrayList();
Map temp = new HashMap();temp.put('set',xxx);temp.put('value',xxx);
list.add(temp);
....有多少個就添加多少,
然後把list添加到最外層的Map對象中;
map.put('optionset',list); key就是json字元中對應的key
拼裝好了map然後就是下一句就搞定了
String josnStr = JSONObject.toJSONString(map);
3. javaweb如何在服務端創建文件(如txt,json等)
File writeName = new File(你要存的地方); // 相對路徑,如果沒有則要建立一個新
//的.txt文件
writeName.createNewFile(); // 創建新文件,有同名的文件的話直接覆蓋
FileWriter writer = new FileWriter(writeName);
BufferedWriter out = new BufferedWriter(writer);
out.write(你要寫入的信息);
4. java如何創建Json文件
json保存的文件也是XML格式的, 講取得的信息轉化為XML格式的,然後讀取的時候 在按照json讀取, json.ToXml() 可以轉化,具體的代碼要自己實現,祝你好運,天天好心情,請採納
5. 用java代碼,從資料庫中取出數據,轉換成json格式的文件,放到指定文件夾中
import org.json.JSONArray;
import org.json.JSONObject;
public void outJson(Object obj) throws Exception {
JSONObject json = new JSONObject(obj, false);
String rr = json.toString(1);
response.setCharacterEncoding("utf-8");
response.getOutputStream().write(rr.getBytes("utf-8"));
}
6. java如何實現txt文本以json格式輸出
在進行流化的時候json.tojson json支持很多方法進行轉化成json進行輸出 可以看看api文檔
7. java創建json文件問題,求大神解答
你使用的是 gson 吧?代碼如下:
importcom.google.gson.JsonArray;
importcom.google.gson.JsonObject;
publicclassApp{
publicstaticvoidmain(String[]args){
JsonArraymils=newJsonArray();
JsonObjectmil=newJsonObject();
mil.addProperty("mil",10);
mil.addProperty("status",1);
mils.add(mil);
JsonObjectbasicMetaInfo=newJsonObject();
basicMetaInfo.add("mils",mils);
JsonObjectresult=newJsonObject();
result.add("basicMetaInfo",basicMetaInfo);
Stringjson=result.toString();
System.out.println(json);
}
}
8. java後台如何生成.json文件
先生成map 然後用alibaba的fastjson,附件中的這個包,里頭有你意想不到的API
例如:
Map map = ......;
map的結構和要生成的字元串結構一致就行,你的optionset在map里頭的結構就是一個list
list optionset= new ArrayList();
Map temp = new HashMap();temp.put('set',xxx);temp.put('value',xxx);
list.add(temp);
....有多少個就添加多少,
然後把list添加到最外層的Map對象中;
map.put('optionset',list); key就是json字元中對應的key
拼裝好了map然後就是下一句就搞定了
String josnStr = JSONObject.toJSONString(map);
9. 用java生成json文件,怎麼編寫
直接調用類庫里的屬性和方法就行,沒必要自己寫啊!你說的源碼是什麼意思?
你這個json格式本身就有問題,不符合標准。
10. java這種格式的json怎麼生成
List json = new AarryList(Nav); Nav bean = new Nav(); beansetId(20140406L); beansetText("檢查記錄"); List list = navServicegettree(nav,lv); beansetChildren(list); jsonadd(bean); return json;java這種格式的json怎麼生成