Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a 3D array out of list in C #

Say my data is like
[{"axis":"NW","value":1.00},{"axis":"SW","value":1.00},{"axis":"EE","value":1.00}]


What type of array is this?
var data = [
[//iPhone
{axis:"Battery Life",value:0.22},
{axis:"Brand",value:0.28},
{axis:"Contract Cost",value:0.29},
{axis:"Design And Quality",value:0.17},
{axis:"Have Internet Connectivity",value:0.22},
{axis:"Large Screen",value:0.02},
{axis:"Price Of Device",value:0.21},
{axis:"To Be A Smartphone",value:0.50}			
]//[//Samsung
{axis:"Battery Life",value:0.27},
{axis:"Brand",value:0.16},
{axis:"Contract Cost",value:0.35},
{axis:"Design And Quality",value:0.13},
{axis:"Have Internet Connectivity",value:0.20},
{axis:"Large Screen",value:0.13},
{axis:"Price Of Device",value:0.35},
{axis:"To Be A Smartphone",value:0.38}
],
[//Nokia Smartphone
{axis:"Battery Life",value:0.26},
{axis:"Brand",value:0.10},
{axis:"Contract Cost",value:0.30},
{axis:"Design And Quality",value:0.14},
{axis:"Have Internet Connectivity",value:0.22},
{axis:"Large Screen",value:0.04},
{axis:"Price Of Device",value:0.41},
{axis:"To Be A Smartphone",value:0.30}
]//;


What I have tried:

List<HCP_Prfm_Chart> lstdtl = new List<HCP_Prfm_Chart>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
lstdtl.Add(new HCP_Prfm_Chart
{
axis = dr["axis"].ToString(),
                
value = Convert.ToInt32(dr["value"])
});
}
HCP_Prfm_Chart[] Myarry = lstdtl.ToArray();
return Json(Myarry, JsonRequestBehavior.AllowGet);


How can i return this type of array back from this function

[{"axis":"NW","value":1.00}],[{"axis":"SW","value":1.00}]
Posted
Updated 26-Sep-17 20:38pm

That is called "JSON Data" and is a standard tranmsfer format, in the same way that XML, is, or CSV.

See here: From zero to hero in JSON with C#[^] it describes it pretty weel, and shows you how to processit very easily into usefull C# data.
 
Share this answer
 
Comments
Member 10408754 27-Sep-17 5:17am    
Thanks for you comment, I am bit confused about JSON the reason why I posted this question because I am having trouble in formatting the data for my D3js radar chart(another question I have posted) https://www.codeproject.com/Questions/1207942/How-do-I-pass-this-value-in-d-js-radar-chart

Would You please look into it and help me in understanding it!!
OriginalGriff 27-Sep-17 5:34am    
Read the article - it explains it a lot better than I could in a little textbox like this!
As OriginalGriff mentioned, it is JSON data. Here is another article that discusses in more detail how to work with JSON data: Working with JSON in C# & VB[^]

The article also lists a number of useful tools for tasks like automatically generating C#/VB code from raw JSON...
 
Share this answer
 
Comments
Member 10408754 27-Sep-17 5:17am    
Same comment:

Thanks for you comment, I am bit confused about JSON the reason why I posted this question because I am having trouble in formatting the data for my D3js radar chart(another question I have posted) https://www.codeproject.com/Questions/1207942/How-do-I-pass-this-value-in-d-js-radar-chart

Would You please look into it and help me in understanding it!!
Graeme_Grant 27-Sep-17 5:24am    
It's an array of objects with two properties: axis and value

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