0
即使我从我的休息服务中返回了Json数据,我的内容标题也显示响应为字符串。这个问题特别发生在ajax函数调用中的post请求中?响应json数据
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">/script>
function authenticate(Source,Destination) {
$.ajax
({
type: 'POST',
url: 'REST/WebService/InsertFeeds',
dataType:'json',
//async: false,
data:{'Source': Source, 'Destination': Destination },
//headers: {
contentType: 'application/json',
//},
error:function()
{
alert("unsuccessfull");
},
success:function(feeds)
{
alert(feeds);
}
});
}
我的REST服务代码数据使用后插入注释:
@Path("/WebService")
public class LoginService
{
@POST
@Path("/InsertFeeds")
@Consumes("application/json")
@Produces("application/json")
public String messageFeed2(@FormParam("Source") String Source,@FormParam("Destination") String Destination)
{
String feeds = null;
try
{
String feedData=null;
ProjectManager projectManager= new ProjectManager();
feedData=projectManager.InsertFeeds(Source,Destination);
feeds=FeedTransformer.UserFeeding(feedData);//converts string in Json format using gson library
} catch (Exception e)
{
System.out.println("error");
}
return feeds;
}
}
您面临的问题是什么? – Veera
Json是一个字符串,所以当然它被检索,它不是一个对象,直到你将它转换为一个 –
Firebug显示数据返回的响应部分不在json内容意味着json对象没有得到返回为什么? – shanky