1

将 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}

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

{"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 对象中删除此“数据”部分?是否可以?

我从这个 URL 访问这些数据。api/matchingservicewebapi/GetUser

4

4 回答 4

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;

这里的工作示例

于 2012-07-12T10:00:16.527 回答
1

采用

<script >
var data = yourJson.data
</script>
于 2012-07-12T10:00:36.167 回答
1

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

于 2012-07-12T10:00:39.800 回答
1

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

于 2012-07-12T10:01:04.513 回答