AngularJS 以正常形式显示 json Format.Need 中的数据?
AngularJS displaying data in json Format.Need it in normal form?
这将如何正常工作?
您好,我创建了一个简单的 Rest 服务:
@GET
@Path("/SayHello")
@Produces(MediaType.APPLICATION_JSON)
public String sayhello(){
String name="Hello";
return name;
}
并使用来自 angular 的 MIME 服务和控制器的 $resource 调用它,如下所示:
service.factory('Tester', function ($resource) {
return $resource('http://localhost:8080/Resource/rest/SayHello', {}, {
test: { method: 'GET',isArray: false ,cache : false },
})
});
在控制器中,我通过测试服务调用 REST 服务:
Tester.test({},function success(response){
console.log("Tester Success: "+JSON.stringify(response));
$scope.output=response;
},
function error(errorResponse){
console.log("Tester Error: "+JSON.stringify(errorResponse));
});
现在在模板 {{output}}
中打印此 "output"
它以 json 格式显示 - {"0":"H","1":"e","2":"l","3":"l","4":"o"}
而不是 'Hello'。
使用 $http
它有效,但不使用 $resource
。我有什么解决办法吗?
提前致谢。
它看起来像是 that 问题的副本。我快速证明了概念,但遇到了同样的问题。简单地说,你可以将你的消息包装成类似的东西
{
"message": "Hello"
}
这将如何正常工作?
您好,我创建了一个简单的 Rest 服务:
@GET
@Path("/SayHello")
@Produces(MediaType.APPLICATION_JSON)
public String sayhello(){
String name="Hello";
return name;
}
并使用来自 angular 的 MIME 服务和控制器的 $resource 调用它,如下所示:
service.factory('Tester', function ($resource) {
return $resource('http://localhost:8080/Resource/rest/SayHello', {}, {
test: { method: 'GET',isArray: false ,cache : false },
})
});
在控制器中,我通过测试服务调用 REST 服务:
Tester.test({},function success(response){
console.log("Tester Success: "+JSON.stringify(response));
$scope.output=response;
},
function error(errorResponse){
console.log("Tester Error: "+JSON.stringify(errorResponse));
});
现在在模板 {{output}}
它以 json 格式显示 - {"0":"H","1":"e","2":"l","3":"l","4":"o"}
而不是 'Hello'。
使用 $http
它有效,但不使用 $resource
。我有什么解决办法吗?
提前致谢。
它看起来像是 that 问题的副本。我快速证明了概念,但遇到了同样的问题。简单地说,你可以将你的消息包装成类似的东西
{
"message": "Hello"
}