Click here to Skip to main content
15,908,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
[{"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"}]


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 .
Posted
Updated 23-Dec-16 22:06pm
Comments
Thomas Daniels 24-Dec-16 2:17am    
This question is tagged as C#, JavaScript, and Java. Which language do you need to parse the JSON in?

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

in JavaScript file:

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


so you can access "rid" variable.
 
Share this answer
 
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>

In this way, you can access any of the attributes. Just implement this same approach in JAVA or C# or whatever.
Edit fiddle - JSFiddle[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900