string 转换成json
我在前台传入了一个劲松对象varUserObject={"user":"aa";};传到后台的时候是{“user”:"aa"}我用JSONObject的fromObjec...
我在前台传入了一个劲松对象var
UserObject = {
"user" : "aa";
};
传到后台的时候是{“user”:"aa"}
我用JSONObject的fromObject(json);来将这个字符串转换为Json对象,
但是总是报Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
我是没有办法了,请帮帮忙,谢谢
package com.satoteam.action;
import java.util.ArrayList;
import net.sf.json.JSONObject;
public class LoginAction {
private String json;
//json={"user":"aa"}
public void setJson(String json) {
System.out.println(json);
JSONObject jo = JSONObject.fromObject(json);
System.out.println("11111"+jo.getString("user"));
this.json = json;
}
}
我用的是json-lib-2.4-jdk15.jar
报的错
2011-5-6 9:39:57 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
警告: Error setting expression 'json' with value '[Ljava.lang.String;@e3404f'
ognl.MethodFailedException: Method "setJson" failed for object com.satoteam.action.LoginAction@1204425 [java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException]
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
/-- Encapsulated exception ------------\
java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException 展开
UserObject = {
"user" : "aa";
};
传到后台的时候是{“user”:"aa"}
我用JSONObject的fromObject(json);来将这个字符串转换为Json对象,
但是总是报Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
我是没有办法了,请帮帮忙,谢谢
package com.satoteam.action;
import java.util.ArrayList;
import net.sf.json.JSONObject;
public class LoginAction {
private String json;
//json={"user":"aa"}
public void setJson(String json) {
System.out.println(json);
JSONObject jo = JSONObject.fromObject(json);
System.out.println("11111"+jo.getString("user"));
this.json = json;
}
}
我用的是json-lib-2.4-jdk15.jar
报的错
2011-5-6 9:39:57 com.opensymphony.xwork2.util.logging.jdk.JdkLogger warn
警告: Error setting expression 'json' with value '[Ljava.lang.String;@e3404f'
ognl.MethodFailedException: Method "setJson" failed for object com.satoteam.action.LoginAction@1204425 [java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException]
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
/-- Encapsulated exception ------------\
java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException 展开
4个回答
2011-05-06
展开全部
你需要用到第三方的lib文件: json-lib。
From Beans to JSON:
class MyBean{
private String name = "json";
private int pojoId = 1;
private char[] options = new char[];
private String func1 = "function(i)";
private JSONFunction func2 = new JSONFunction(new String[],"return this.options[i];");
// getters & setters
...
}
JSONObject jsonObject = JSONObject.fromObject( new MyBean() );
System.out.println( jsonObject );
/* prints
{"name":"json","pojoId":1,"options":["a","f"],
"func1":function(i),
"func2":function(i)}
*/
在你这里就是:JSONObject jsonObject = JSONObject.fromObject(user );
From JSON to Beans:
String json = "";
JSONObject jsonObject = JSONObject.fromObject( json );
BeanA bean = (BeanA) JSONObject.toBean( jsonObject, BeanA.class );
在你这里就是:
JSONObject jsonObject = JSONObject.fromObject( json );
User bean = (User) JSONObject.toBean( jsonObject, User.class );
另外,站长团上有产品团购,便宜有保证
From Beans to JSON:
class MyBean{
private String name = "json";
private int pojoId = 1;
private char[] options = new char[];
private String func1 = "function(i)";
private JSONFunction func2 = new JSONFunction(new String[],"return this.options[i];");
// getters & setters
...
}
JSONObject jsonObject = JSONObject.fromObject( new MyBean() );
System.out.println( jsonObject );
/* prints
{"name":"json","pojoId":1,"options":["a","f"],
"func1":function(i),
"func2":function(i)}
*/
在你这里就是:JSONObject jsonObject = JSONObject.fromObject(user );
From JSON to Beans:
String json = "";
JSONObject jsonObject = JSONObject.fromObject( json );
BeanA bean = (BeanA) JSONObject.toBean( jsonObject, BeanA.class );
在你这里就是:
JSONObject jsonObject = JSONObject.fromObject( json );
User bean = (User) JSONObject.toBean( jsonObject, User.class );
另外,站长团上有产品团购,便宜有保证
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你需要用到第三方的lib文件: json-lib。
From Beans to JSON:
class MyBean{
private String name = "json";
private int pojoId = 1;
private char[] options = new char[];
private String func1 = "function(i)";
private JSONFunction func2 = new JSONFunction(new String[],"return this.options[i];");
// getters & setters
...
}
JSONObject jsonObject = JSONObject.fromObject( new MyBean() );
System.out.println( jsonObject );
/* prints
{"name":"json","pojoId":1,"options":["a","f"],
"func1":function(i),
"func2":function(i)}
*/
在你这里就是:JSONObject jsonObject = JSONObject.fromObject(user );
From JSON to Beans:
String json = "";
JSONObject jsonObject = JSONObject.fromObject( json );
BeanA bean = (BeanA) JSONObject.toBean( jsonObject, BeanA.class );
在你这里就是:
JSONObject jsonObject = JSONObject.fromObject( json );
User bean = (User) JSONObject.toBean( jsonObject, User.class );
From Beans to JSON:
class MyBean{
private String name = "json";
private int pojoId = 1;
private char[] options = new char[];
private String func1 = "function(i)";
private JSONFunction func2 = new JSONFunction(new String[],"return this.options[i];");
// getters & setters
...
}
JSONObject jsonObject = JSONObject.fromObject( new MyBean() );
System.out.println( jsonObject );
/* prints
{"name":"json","pojoId":1,"options":["a","f"],
"func1":function(i),
"func2":function(i)}
*/
在你这里就是:JSONObject jsonObject = JSONObject.fromObject(user );
From JSON to Beans:
String json = "";
JSONObject jsonObject = JSONObject.fromObject( json );
BeanA bean = (BeanA) JSONObject.toBean( jsonObject, BeanA.class );
在你这里就是:
JSONObject jsonObject = JSONObject.fromObject( json );
User bean = (User) JSONObject.toBean( jsonObject, User.class );
追问
我用的是struts2的json-lib但是一直报错,是为什么呢
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
虽然时间已经过去那么就了,但我还是回答,这里的警告是说,json参数的类型是String ,从这段话中,我可以猜到,JSON是用反射的,获取对象的set访问器,也就是说这里的错误就是:参数JSON必须时一个实体 bean ,才能使用
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
少了 commons-long.jar包
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询