如何按名称拆分我的json值 [英] How do I split my json value , by its name

查看:91
本文介绍了如何按名称拆分我的json值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[{"rid":5,"latitude":6.95653333333333,"longitude":79.8554666666667,"trackerid":"01154524SKY7389","heading":39,"ReceivedUTC":"11/28/2016 12:42:16 AM"},{"rid":5,"latitude":6.95358333333333,"longitude":79.8539333333333,"trackerid":"01154524SKY7389","heading":244,"ReceivedUTC":"11/29/2016 12:42:17 AM"},{"rid":5,"latitude":6.95358333333333,"longitude":79.8539166666667,"trackerid":"01154524SKY7390","heading":48,"ReceivedUTC":"11/30/2016 12:42:16 AM"},{"rid":5,"latitude":6.95363333333333,"longitude":79.8541833333333,"trackerid":"01154524SKY7390","heading":7,"ReceivedUTC":"12/22/2016 12:42:09 AM"}]





如果我的跟踪器ID是以json格式从db获取大量数据改变我需要做不同的操作,所以我需要拆分这个,我需要保存在其他一些,数组变量或json



我试过的:



新手我不知道尝试。



Am taking bulk of data from db in json format , if my tracker id change i need to do different operation , so i need to split this and i need to save in some other, array variable or json

What I have tried:

Am new to this i have no idea to try .

推荐答案

你好

如果你从控制器那里得到它:JsonConvert.SerializeObject方法,

你可以试试:


JavaScript文件中的




Hello
If you have get it from controller by: "JsonConvert.SerializeObject" method,
you can try :

in JavaScript file:

function myFunction(response)
{
  var _Data = JSON.Parse(response);
  var _rid = _Data.rid;
}





所以你可以访问rid变量。



so you can access "rid" variable.


研究这个JavaScript中的示例(带注释),毕竟JSON遵循JS语法:

Study this example in JavaScript (with comments), after all JSON follow JS syntax:
<script>

var JSON_String = '[{"rid":5,"latitude":6.95653333333333,"longitude":79.8554666666667,"trackerid":"01154524SKY7389","heading":39,"ReceivedUTC":"11/28/2016 12:42:16 AM"},{"rid":5,"latitude":6.95358333333333,"longitude":79.8539333333333,"trackerid":"01154524SKY7389","heading":244,"ReceivedUTC":"11/29/2016 12:42:17 AM"},{"rid":5,"latitude":6.95358333333333,"longitude":79.8539166666667,"trackerid":"01154524SKY7390","heading":48,"ReceivedUTC":"11/30/2016 12:42:16 AM"},{"rid":5,"latitude":6.95363333333333,"longitude":79.8541833333333,"trackerid":"01154524SKY7390","heading":7,"ReceivedUTC":"12/22/2016 12:42:09 AM"}]';

// parse it into an array of JavaScript objects
var obj = JSON.parse(JSON_String);

// loop thru the array
for (i = 0;i < obj.length; i++) { 

	// print out the attribute values of each object
	for(var attribute in obj[i]) {
    	document.write(attribute + ": " + obj[i][attribute] + "<br>");
	}
    
    document.write("+++++++++++++++++++++++++++++++<br>");

}
</script>



通过这种方式,您可以访问任何属性。只需在JAVA或C#或其他任何方法中实现相同的方法。

编辑小提琴 - JSFiddle [ ^ ]


这篇关于如何按名称拆分我的json值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆