FIleText转换为JSONObject对象
Posted 北极星的小乌龟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FIleText转换为JSONObject对象相关的知识,希望对你有一定的参考价值。
1 package com.beijxing.TestMain; 2 3 import java.io.File; 4 import java.io.IOException; 5 6 import org.apache.commons.io.FileUtils; 7 8 import net.sf.json.JSONObject; 9 10 /** 11 * 12 * @author 作者 : ywp 13 * @version 创建时间:2016年10月25日 下午10:30:14 14 */ 15 public class TestJson2 { 16 public static void main(String[] args) { 17 try { 18 fileToJson(); 19 } catch (IOException e) { 20 e.printStackTrace(); 21 } 22 } 23 public static void fileToJson() throws IOException{ 24 File file = new File(TestJson2.class.getResource("/jsonText.json").getFile());//获取项目根路径下的文件 25 String content = FileUtils.readFileToString(file); 26 JSONObject jsonObject = JSONObject.fromObject(content); 27 System.out.println("jsonObject="+jsonObject); 28 } 29 }
以上是关于FIleText转换为JSONObject对象的主要内容,如果未能解决你的问题,请参考以下文章
Java自定义方法转换前端提交的json字符串为JsonObject对象
AsyncTask #3 解析 JSON 对象时出错。字符串无法转换为 JSONObject
解析JSON对象的AsyncTask#3错误。 String无法转换为JSONObject