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