I have an arrayList in C# where i store data of ip's and isp's and count as follows from a mysql table,
ArrayList conRc = new ArrayList();
while (readIp.Read())
{
string ipVal = readIp.GetString(0);
string ispVal = readIp.GetString(1);
int conLvlVal = readIp.GetInt32(2);
conRc.Add(new ConfidenceLvl(ipVal,ispVal,conLvlVal));
}
This is my ConfidenceLvl Class,
public class ConfidenceLvl
{
private string ip;
private string isp;
private int conLvl;
public string Ip
{
get { return ip; }
set { ip = value; }
}
public string Isp
{
get { return isp; }
set { isp = value; }
}
public int ConLvl
{
get { return conLvl; }
set { conLvl = value; }
}
public ConfidenceLvl(string ipVal, string ispVal, int conLvlVal) {
this.conLvl = conLvlVal;
this.ip = ipVal;
this.isp = ispVal;
}
}
I wan to pass this to javascript so that i can make use of these value to create a chart through jqPlot. Please help on this one I used this method to pass my values to javascript but it all goes as one string. I wan to take these values separately and work with them in javascript. Please help me. Thank you very much.
EDIT: Thanks to Dominik Kirschenhofer, I finally wound up with this after successfully parsing the to javascript. May i know how to manipulate these data? like getting records 1 by 1?? i tried to but none worked,
<asp:HiddenField ID="correlate" value= "" runat="server" />
<script language="javascript" type="text/javascript">
var jsonString = document.getElementById('correlate').value;
var arr_from_json = JSON.parse(jsonString);
</script>
The json string is as follows,
[{"Ip":"0","Count":"10"},{"Ip":"1","Count":"11"},{"Ip":"2","Count":"12"},{"Ip":"3","Count":"13"},{"Ip":"4","Count":"14"},{"Ip":"5","Count":"15"},{"Ip":"6","Count":"16"},{"Ip":"7","Count":"17"},{"Ip":"8","Count":"18"},{"Ip":"9","Count":"19"}]
May i know how can i work with these records :)
EDIT: SOLVED IT
<asp:HiddenField ID="correlate" value= "" runat="server" />
<script language="javascript" type="text/javascript">
var jsonString = document.getElementById('correlate').value;
jsonString = "{\"corrData\":" + jsonString + "}";
var arr_from_json = JSON.parse(jsonString);
alert(Number(arr_from_json.corrData[2].Ip)+1);
</script>
I added corrData so that i can call it by an Integer Id like in an array. :) thanks for your help guys :) if there is better way..please let me know :)