删除JSON的一部分

时间:2012-07-12 09:57:46

标签: javascript json

当向客户端发送json数据时,我得到这样的数据。

{"Data":{"rows":[{"id":1,"cell":["1","amila","amila","False"]},{"id":2,"cell":["2","rakhitha","rakhitha","False"]},{"id":3,"cell":["3","Chathura","Chathura","False"]},{"id":4,"cell":["4","Geethaga","Geethaga","False"]}]},"JsonRequestBehavior":0}

但我想获取没有“Data”属性的数据。像这样,

{"rows":[{"id":1,"cell":["1","amila","amila","False"]},{"id":2,"cell":["2","rakhitha","rakhitha","False"]},{"id":3,"cell":["3","Chathura","Chathura","False"]},{"id":4,"cell":["4","Geethaga","Geethaga","False"]}]}

如何从json对象中删除此“数据”部分?有可能吗?

我从此网址访问此数据。 API / matchingservicewebapi /的getUser

4 个答案:

答案 0 :(得分:6)

这样做:

var json = {"Data":{"rows":[{"id":1,"cell":["1","amila","amila","False"]},{"id":2,"cell":["2","rakhitha","rakhitha","False"]},{"id":3,"cell":["3","Chathura","Chathura","False"]},{"id":4,"cell":["4","Geethaga","Geethaga","False"]}]},"JsonRequestBehavior":0};

​json = json.Data;

Working example here

答案 1 :(得分:1)

使用

<script >
var data = yourJson.data
</script>

答案 2 :(得分:1)

如果您管理服务器(在url:api / matchingservicewebapi / GetUser上),您需要更改那里的输出。

答案 3 :(得分:1)

例如,如果您在results变量中获得JSON结果,则可以执行results = results.Data