Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ID Name Questions

1 OLAM "Produto prefer":"Algodão","Plantou algodão":"Sim"
2 OLAM "Produto prefer:"Feijão Buer","Plantou algodão":"Não"
3 OLAM "Produto prefer":"Buer","Plantou algodão":"Jao"

from the above i split json quesions as follows

ID Name Produto prefer Plantou algodão
1 OLAM
2 OLAM
3 OLAM

for that i written code as follows

int columnindex = 43;
foreach (DataRow row in dtFarmerFarmReports.Rows)
{
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(row["farm_detailsdata"].ToString());
string str = string.Empty;

List<string> lst = new List<string>();
lst.AddRange(dict.Keys);
var distinctList = lst.Distinct().ToList();

foreach (var data in distinctList)
{
columnindex++;
worksheet.Cells[2, columnindex].Value = data;
}
}

i want to display the answers for each questions

i want output as follows

ID Name Produto prefer Plantou algodão
1 OLAM Algodao Sim
2 OLAM Feijao Buer Nao
3 OLAM Buer Jao

for getting below output what changes i have to made in my code to display answers.

What I have tried:

ID Name Questions

1 OLAM "Produto prefer":"Algodão","Plantou algodão":"Sim"
2 OLAM "Produto prefer:"Feijão Buer","Plantou algodão":"Não"
3 OLAM "Produto prefer":"Buer","Plantou algodão":"Jao"

from the above i split json quesions as follows

ID Name Produto prefer Plantou algodão
1 OLAM
2 OLAM
3 OLAM

for that i written code as follows

int columnindex = 43;
foreach (DataRow row in dtFarmerFarmReports.Rows)
{
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(row["farm_detailsdata"].ToString());
string str = string.Empty;

List<string> lst = new List<string>();
lst.AddRange(dict.Keys);
var distinctList = lst.Distinct().ToList();

foreach (var data in distinctList)
{
columnindex++;
worksheet.Cells[2, columnindex].Value = data;
}
}

i want to display the answers for each questions

i want output as follows

ID Name Produto prefer Plantou algodão
1 OLAM Algodao Sim
2 OLAM Feijao Buer Nao
3 OLAM Buer Jao

for getting below output what changes i have to made in my code to display answers.
Posted
Updated 10-May-18 15:48pm

1 solution

I see no HTML or javascript here. If you have the data as JSON, why don't you pass it to your client and deal with it there? Or, whatever you're seeing change that value on the server to contain the data you want to display?
 
Share this answer
 
Comments
[no name] 11-May-18 0:37am    
i want to display value for each key.

using my below code what changes i have to made to get the answers for each questions

My code as follows


int columnindex = 43;
foreach (DataRow row in dtFarmerFarmReports.Rows)
{
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(row["farm_detailsdata"].ToString());
string str = string.Empty;

List<string> lst = new List<string>();
lst.AddRange(dict.Keys);
var distinctList = lst.Distinct().ToList();

foreach (var data in distinctList)
{
columnindex++;
worksheet.Cells[2, columnindex].Value = data;
}
}

output i want as follows

ID Name Produto prefer Plantou algodão
1 OLAM Algodao Sim
2 OLAM Feijao Buer Nao
3 OLAM Buer Jao
[no name] 16-May-18 10:04am    
how to display values for each key in dictionary


in excel json string as follows

id name Questions

1 OLAM "Produto prefer":"Algodao,"Plantou algodão":"Sim"
2 OLAM "Produto prefer":"Feijao Buer,"Plantou algodão":"Sim"

My code as follows

int columnindex = 43;
List<string> lst = new List<string>(); // declare "lst" here

foreach (DataRow row in dtFarmerFarmReports.Rows)
{
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(row["farm_detailsdata"].ToString());
string str = string.Empty;
lst.AddRange(dict.Keys); // add the keys inside your foreach
lst.AddRange(dict.Values);
}

var distinctList = lst.Distinct().ToList(); // perform the Distinct outside the foreach
foreach (var data in distinctList)
{
columnindex++;
worksheet.Cells[2, columnindex].Value = data;
}

When i run the above code i get output as follows

ID Name Produto prefer Plantou algodão
1 OLAM
2 OLAM


from the above i want output as follows

ID Name Produto prefer Plantou algodão
1 OLAM Algodao Sim
2 OLAM Feijao Buer Sim

from the above code what changes i have to made to display value for each key.
[no name] 16-May-18 21:44pm    
how to do please let me know i am new this one.

how to display value for each key.

in excel json string as follows

id name Questions

1 OLAM "Produto prefer":"Algodao,"Plantou algodão":"Sim"
2 OLAM "Produto prefer":"Feijao Buer,"Plantou algodão":"Sim"

My code as follows

int columnindex = 43;
List<string> lst = new List<string>(); // declare "lst" here

foreach (DataRow row in dtFarmerFarmReports.Rows)
{
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(row["farm_detailsdata"].ToString());
string str = string.Empty;
lst.AddRange(dict.Keys); // add the keys inside your foreach
lst.AddRange(dict.Values);
}

var distinctList = lst.Distinct().ToList(); // perform the Distinct outside the foreach
foreach (var data in distinctList)
{
columnindex++;
worksheet.Cells[2, columnindex].Value = data;
}

When i run the above code i get output as follows

ID Name Produto prefer Plantou algodão
1 OLAM
2 OLAM


from the above i want output as follows

ID Name Produto prefer Plantou algodão
1 OLAM Algodao Sim
2 OLAM Feijao Buer Sim

from the above code what changes i have to made to display value for each key.
[no name] 20-May-18 21:23pm    
how to do. please let me know

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