Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai,
i get some array value like this from database using Jquery
[{"Processid":"3","ProcessName":"Fax Queue","Total":"30"}


I need to Split this array in Jquery

What I have tried:

JavaScript
$.ajax({
	type:"POST",
	url:"http://172.16.3.19/php/webservice/GetClientWiseProcess.php",data:{ClientID:CID}
	$.post( $("#myForm").attr("action"),
	$('#str').val(JSON.stringify(jsarray)),  
	//$("#myForm :input").serializeArray(), 
	function(info){ $("#result").html(info); 
	});
});
Posted
Updated 10-Feb-17 20:05pm
v2
Comments
Karthik_Mahalingam 10-Feb-17 14:08pm    
what is your expected output?
Nataraj Pandiyan 10-Feb-17 15:01pm    
the array value IS [{"Processid":"3","ProcessName":"Fax Queue","Total":"30"}

I want to send the array value to table like
Processid ProcessName Total
3 Fax Queue 30

and the processname column is a button

Karthik_Mahalingam 10-Feb-17 15:02pm    
are you getting the json array in
JSON.stringify(jsarray) ?
Karthik_Mahalingam 10-Feb-17 15:02pm    
are you getting the json array in
JSON.stringify(jsarray) ?
Nataraj Pandiyan 10-Feb-17 16:19pm    
yes

Do you mean displaying key value? If that the case, here is an example, assuming the application is using jQuery

JavaScript
<script>
    var x = [{ "Processid": "3", "ProcessName": "Fax Queue", "Total": "30" }];

    jQuery.each(x[0], function (key, value) {
        console.log(key, value);
        //write some code here to build the table? I'm just guessing
    });
</script>


And this is the output.

Processid 3
ProcessName Fax Queue
Total 30
 
Share this answer
 
v2
JSON is used to exchange data in a structure form of strings between machines, it follows JavaScript syntax of objects and arrays. When you receive a JSON input, always parse it into a JavaScript object or array of objects before further processing, e.g.
<script>
// JSON string received from server
jsonString = '[{"Processid":"4","ProcessName":"Fax Queue","Total":"31"}, {"Processid":"5","ProcessName":"Phone Queue","Total":"32"}]';

// Parse to an array of JSON objects
var jsonArray = JSON.parse(jsonString);

for (i=0;i<jsonArray.length;i++) {
   alert(jsonArray[i].Processid + ", " + jsonArray[i].ProcessName + ", " + jsonArray[i].Total);
}
</script>
See demo at Edit fiddle - JSFiddle[^]
On the other hand, to output JSON data to another machine, always stringify it to string first, see How to write JSON data in ajax[^]
 
Share this answer
 
v5

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