jquery的ajax,取回的json串,怎么把null过滤成oracle 空串 和 null

jquery的ajax,取回的json串,怎么把null过滤成空串_百度知道
jquery的ajax,取回的json串,怎么把null过滤成空串
提问者采纳
null}JSONObject jsonObj = new JSONObject(json);获取JSON中SSGM的值便于判断if(null == SSGM) {
jsonObj ,&如果为null那么将SSGM的值赋值为&quot,如果可以的话在写json的时候就做判断.put(&}不知道你的需求是什么;&#47。如果json={&);&quot.get(&/SSGM&SSGM&quot可以重新赋值;)/&String SSGM = jsonOSSGM&;/
来自团队:
其他类似问题
为您推荐:
json的相关知识
其他1条回答
&quot参数==null?&
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁jquery解析json(从服务器返回的字符串)怎么解析-Web开发/Ajax-ajax-电脑编程网jquery解析json(从服务器返回的字符串)怎么解析-Web开发/Ajax作者:weitongyixun 和相关&&json 在里返回的是字符串形式如下:{&title&:&测试标题&,&name&:&张三&,&address&:&大连&}{&title&:&测试标题123&,&name&:&张三123&,&address&:&大连123&}用怎么取解析啊。因为有多条数据& 我用$.each(json,function(i){}去弄没有反映啊。。高手帮忙------回答---------------其他回答(5分)---------多条应该是数组[{},{},{},{},{},{},{},{}]------其他回答(5分)---------按照你的意思,以字符串方式接受JSON,应该需要做一次对象化处理var dataObj=eval(&(&+json+&)&);//转换为json对象& $.each(dataObj,fucntion(index,item){&
if(index==0){&
& //继续 &
}& //输出每个子对象的名称和值&
&alert(&title:&+item.title+&,name:&+item.name+&,address:&+item.address);& }) ;注:对于一般的js生成json对象,只需要将$.each()方法替换为for语句即可,其他不变。& 这种方式也适合以普通scipt方式获取json对象2.对于返回的JSON字符串,如果jquery异步请求将type(配置属性)设为“json”,或者利用$.getJSON()方法获得服务器返回,那么就不需要eval()方法了,因为这时候得到的结果已经是json对象了,只需直接调用该对象即可,这里以$.getJSON方法为例说明数据处理方法:& $.getJSON(&/&,{param:&&},function(json){& //此处返回的data已经是json对象& $.each(json,function(index,item){& if(index==0){& //同countinue,返回false同break& }& alert(&title:&+item.title+&,name:&+item.name+&,address:&+item.address);& })& });& ------其他回答(5分)---------引用 3 楼 ofacop 的回复:按照你的意思,jquery以字符串方式接受JSON,应该需要做一次对象化处理var dataObj=eval(&(&+json+&)&);//转换为json对象 $.each(dataObj,fucntion(index,item){
if(index==0){
} //输出每个子对象的名称和值
alert……从1.4开始,jquery就放弃eval方法了------其他回答(5分)---------$.({ &
dataType:&json&, &
type:&GET&, &
error:function(){}, &
success:function(data){ &
$.each(data,function(i,v){ &
值 v.title/v.name... &
}});------其他回答(5分)---------引用 4 楼 ferock 的回复:引用 3 楼 ofacop 的回复:按照你的意思,jquery以字符串方式接受JSON,应该需要做一次对象化处理var dataObj=eval(&(&+json+&)&);//转换为json对象$.each(dataObj,fucntion(index,item){if(index==0){ //继续}//输出每个子对象的名称和值……function(data) { &
json = eval(&(& + data + &)&); &
// do something with json仍然是解决问题的一种方法。------其他回答(15分)---------CSS code
{&title&:&测试标题&,&name&:&张三&,&address&:&大连&}{&title&:&测试标题123&,&name&:&张三123&,&address&:&大连123&}
这个json格式是错误的,应该有逗号分隔对象的。
[{&title&:&测试标题&,&name&:&张三&,&address&:&大连&},{&title&:&测试标题123&,&name&:&张三123&,&address&:&大连123&}]
这样就可以了
function showData() {
var data = eval('[{&title&:&测试标题&,&name&:&张三&,&address&:&大连&},{&title&:&测试标题123&,&name&:&张三123&,&address&:&大连123&}];');
var o = eval(data);//将json字符串转换成js对象
for (var i in o) {//循环json对象数组
for (var key in o[i]) {//循环json对象中的属性和值
alert(&field:& + key + &, value:& + o[i][key]);
相关资料:|||||||jquery解析json(从服务器返回的字符串)怎么解析-Web开发/Ajax来源网络,如有侵权请告知,即处理!编程Tags:                &                    基于jquery-ajax的json_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
基于jquery-ajax的json
上传于||文档简介
&&基​于​j​Q​u​e​r​y​.​g​e​t​J​S​O​N​和​j​Q​u​e​r​y​+​a​j​a​x​+​j​s​o​n​的​两​种​方​式​的​J​S​O​N​前​后​台​交​互​,​J​S​O​N​传​到​后​台​接​收​,​处​理​完​了​返​回​J​S​O​N​到​前​台​展​示​,​非​常​易​懂​,​同​时​也​给​出​心​得​体​会​,​有​文​档​有​可​运​行​源​码​(​C​S​D​N​上​面​)​,​有​注​释​。
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
下载文档到电脑,查找使用更方便
还剩5页未读,继续阅读
你可能喜欢技术交流群:jquery - Using ajax to send JSON to an action, parameter is null (returns internal server error 500) - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
I'm trying to use ajax and JSON to get a result back from an action, and where it's working perfectly fine on different pages/actions, this one just won't work.
My Javascript:
var lookup = $("#textbox").val();
url: '/Controller/GetId',
type: 'POST',
dataType: 'json',
data: lookup,
contentType: 'application/ charset=utf-8',
success: function (data) {
My action:
public ActionResult GetId(string lookup)
ActionResult result = View();
Order order =
.Where(o =& o.Code == lookup)
.FirstOrDefault();
result = Json(order.Id.ToString());
Now, I've seen the following situations, all of which I can't really explain:
With the code as above, console.log will display everything fine, the Ajax method throws a 500 internal server error and my breakpoint in my action is not hit (like the action is not called or something?).
With the code as above, except using JSON.stringify around lookup, my breakpoint is hit, but the parameter is NULL. When I continue to debug through the action, the debugger.exe will freeze and crash.
I have a similar situation on a different page, it posts a list as JSON.stringify, my action saves it to the db and returns a result message. This works perfectly fine! I'm completely stumped as to why the above won't work.
I've narrowed it down (just a little bit): turns out the Error 500 Internal Server Error was being thrown because the code inside my action did not handle a null value correctly. Since the parameter is always null, because the JSON isn't sent (correctly), it would always break/crash. I've added a catch now, so JSON will correctly return an error now (saying that my order could not be found).
I'm not sure why this situation doesn't work, while my other does. But, the solution was to pass a model instead of a plain string and using stringify on the entire model. Finally, my action needed to accept a model as well:
var lookup = { lookup: $("#textbox").val() };
url: '/Controller/GetId',
type: 'POST',
dataType: 'json',
data: JSON.stringify(lookup),
contentType: 'application/ charset=utf-8',
success: function (data) {
public ActionResult GetId(Order model)
ActionResult result = View();
Order order =
.Where(o =& o.Lookup == model.Lookup)
.FirstOrDefault();
result = Json(order.Id.ToString());
var lookup = $("#textbox").val();
url: '/Controller/GetId',
type: 'POST',
dataType: 'json',
data: {lookup: JSON.stringify(lookup)}, // change this
contentType: 'application/ charset=utf-8',
success: function (data) {
49.5k133059
I got this working approach all over my code:
var oldSearchId = '@ViewBag.OldSearchId';
var description = $("#Description").val();
var model = { oldSearchId: oldSearchId, newSearchName: searchName, newSearchDescription: description };
url: '@Url.Action("SaveSearchAs", "Search")',
contentType: 'application/ charset=utf-8',
type: 'POST',
dataType: 'html',
data: JSON.stringify(model)
Note the model creation is JS way and then used in JSON.Stringify.
2,76711336
I think you are missing JsonRequestBehavior.AllowGet as :
result = Json(order.Id.ToString(),JsonRequestBehavior.AllowGet);
and correct url as :
url: '/Controller/GetId',
&---instead of 'Controller' give your controller name here
and there is one more problem in your case is that you are using
contentType: 'application/ charset=utf-8' means you are sending json in your ajax request and your data:lookup is not proper json then use JSON.stringify() to convert it to proper Json format.
12.9k31442
var lookup = $("#textbox").val();
url: '@Url.Action("GetId", "Controller")',
type: 'POST',
dataType: 'json',
data: lookup,
contentType: 'application/ charset=utf-8',
success: function (data) {
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 jsonconfig 过滤null 的文章

 

随机推荐