通过前天数据生成json型数据;然后用org.json解析;
但是当其中的项value为空时;就异常了?这种情况怎么避免呢?
前台用户填写信息的时候有的项不是必填项;可以为空的啊?例子:public void input(){
 String str = [{eName:11,eOne:}]
List<Object> userOpHisList =new ArrayList<Object>();
JSONArray jarrs = null;
try {
jarrs = new JSONArray(str);
} catch (JSONException e1) {
e1.printStackTrace();
}    
for(int i=0;i<jarrs.length();i++){  
try {
String s=String.valueOf(jarrs.getJSONObject(i));
// 把JSON按对象 分组(成串)--->JSONObject(s);
JSONObject jObj = null;
jObj = new JSONObject(s);
 
        System.out.println(jObj.get("eName"));
 

System.out.println(jObj.get("eOne"));
 
} catch (JSONException e) {
e.printStackTrace();
}//把json对象串放入JSON对象    
}
}
这里eOne为空时就异常了;eOne不为空正确;怎样让eOne为空时;取的值为 空 “”;而不异常啊;

解决方案 »

  1.   

    哦:手敲的 字符串 str 少了引号;String str = "[{eName:11,eOne:}]";
      

  2.   

    System.out.println(jObj.get("eOne")==null?"":jObj.get("eOne"))
      

  3.   

    不行啊  这样也异常 
    好像就不能到这来?
    jObj.get("eOne")==null
      

  4.   

    改成如下试试看:String str = "[{eName:'11',eOne:''}]";
      

  5.   

    这样当然可以了。问题是前台读取的数据不是这样的啊前台用这个 
    Ext.form.Checkbox让用户勾选;当选中时为 true;
    当用户不选的时候  值就没有;而不是 '';Value.length ==0前台代码:
    header:'是否完成',
    dataIndex:'sfwc',
    editor:new Ext.grid.GridEditor(new Ext.form.Checkbox({
    //allowBlank:false
    width:10
    })),
    renderer:function(value){
    return value? '是':'';
    }