当前位置: 动力学知识库 > 问答 > 编程问答 >

how to do Json parsing Using newtonsoft.json in C#.net

问题描述:

{"Contacts":[{"number":"+919632545302"} ,

{"number":"09868333140"},{"number":"099-713-55036"}]}

This My Json Data i want Parse and Store all Phone number in String by comma separated.

string="+919632545302,09868333140,099-713-55036"

please help me i have tried but i am unable to do this .

网友答案:

Use @ at the beginning of your JSON string and escape " character by doubling each of them ("") :

string data = @"{""Contacts"":[{""number"":""+919632545302""} 
, 
 {""number"":""09868333140""}  
,  
{""number"":""099-713-55036""}]}";

Then you can do this to get all contact numbers as comma separated string :

JObject json = JsonConvert.DeserializeObject<JObject>(data);
JArray contacts = (JArray)json["Contacts"];
string result = string.Join(",", contacts.Select(o => o["number"].ToString()));
Console.WriteLine(result);
分享给朋友:
您可能感兴趣的文章:
随机阅读: