通过前天数据生成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为空时;取的值为 空 “”;而不异常啊;
但是当其中的项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为空时;取的值为 空 “”;而不异常啊;
解决方案 »
- javascript ajax.net用js调用后台函数问题
- GBK与UTF的转换
- 用表格做下拉菜单会动怎么办?
- 键盘的控制问题,麻烦大家
- var SendToValueArray = parwin.document.all.hdnTxtSendTo.value.split(",");谁能告诉我其中的parwin对象是什么,从哪里可以找到帮助吗?
- 如何能将一个页面中text的值传到另一页面的text中,不全部刷新另一页面
- 请教如何取得ie中一个元素到底是显示的还是隐藏的?
- 能否重载web页面的一些方法,如document.onclick()
- jsp网页中提交表单
- jsFileReader读取本地text出现乱码求解决
- javascript里面怎么给url参数赋值?
- jquery如何删除重复DIV,等高手
好像就不能到这来?
jObj.get("eOne")==null
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? '是':'';
}