日期:2014-05-20  浏览次数:20638 次

求助String转JSONObject问题
public static void func()
  {
  String str="{\"name\":\"fabregas\", \"country\":\"[]\"}"; //实验数据1
   
  String ss="{\"name\":{\"country\":\"[]\"}}"; //实验数据2
   

  net.sf.json.JSONObject jsonStr= net.sf.json.JSONObject.fromObject(str);
  System.out.println(jsonStr);  
   
  net.sf.json.JSONObject jsonSs= net.sf.json.JSONObject.fromObject(ss);
  System.out.println(jsonSs);  
  }


执行结果:
{"name":"fabregas","country":"[]"}
{"name":{"country":[]}}


求助: 实验数据2丢失了[]上的引号?请问如何避免这个问题?


问题2:
  如果一个字符串是被双引号引起来的,则如何转化为json格式
  例如:
  字符串"{"name" : ""hello""}"能否转化为json格式

------解决方案--------------------
"{"name" : ""hello""}"

这本身就是JSON数据格式?还要怎么转呢?