即使我从我的休息服务返回了 Json 数据,我的内容标题也将响应显示为字符串。这个问题特别发生在 ajax 函数调用中的 post 请求中?
<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);
}
});
}
使用 post annotation 插入数据的我的 Rest Service 代码:
@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;
}
}