Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ID Name Questions

1 Test "Produto prefer":"Algodão","Plantou algodão":"Sim"
2 Testb "Produto prefer:"Feijão Buer","Plantou algodão":"Não"
3 Testc "Produto prefer":"Buer","Plantou algodão":"Jao"
4 Testd "Produto prefer":"Alaer","Plantou algodão":"Vio"

from the above i want output as follows


The above json string questions column, put into all the questions into column header in excel

ID Name Produto prefer Plantou algodão Produto prefer Plantou algodão Produto prefer Plantou algodão Produto prefer Plantou algodão


For the above 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.Values);

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

Because of all id have same questions, i am getting all id questions using loop only answers will differ for all id.

from the above output how to remove the duplicates id questions and bind the answers for based on each id

Excepted output as follows

ID Name Produto prefer Plantou algodão

1 Test Algodão SIm
2 Testb Feijão Buer Nao
3 Testc Buer Jao
4 Testd Alaer Vio


from my above what changes i have to do to get the excepted output

What I have tried:

ID Name Questions

1 Test "Produto prefer":"Algodão","Plantou algodão":"Sim"
2 Testb "Produto prefer:"Feijão Buer","Plantou algodão":"Não"
3 Testc "Produto prefer":"Buer","Plantou algodão":"Jao"
4 Testd "Produto prefer":"Alaer","Plantou algodão":"Vio"

from the above i want output as follows


The above json string questions column, put into all the questions into column header in excel

ID Name Produto prefer Plantou algodão Produto prefer Plantou algodão Produto prefer Plantou algodão Produto prefer Plantou algodão


For the above 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.Values);

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

Because of all id have same questions, i am getting all id questions using loop only answers will differ for all id.

from the above output how to remove the duplicates id questions and bind the answers for based on each id

Excepted output as follows

ID Name Produto prefer Plantou algodão

1 Test Algodão SIm
2 Testb Feijão Buer Nao
3 Testc Buer Jao
4 Testd Alaer Vio


from my above what changes i have to do to get the excepted output
Posted
Comments
[no name] 9-May-18 1:15am    
please let me know how to do.

i am new to json. how to remove the json duplicates value.

i stroed json in dictionary and stored that dictionary value in List.

how to compare dicitionary value and list value.

if it is same value remove the duplicates. using my above code how to do in c#
Nathan Minier 10-May-18 7:25am    
It's not JSON by the time it hits your foreach loop, it's a Dictionary<string,string>. From there it's not a question of filtering JSON (which is really just a formatted string), it's a question of whether you want to filter keys or values, and establishing a mechanism to ensure uniqueness.
Jinto Jacob 23-May-18 2:46am    

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