-2
{"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 .

6
  • stackoverflow.com/a/2191164/2179864 Commented Aug 26, 2014 at 4:24
  • But i am unable to declare value please help me in that string Jsondata= ' {"Contacts":['+'{"number":"+919632545302"} ,'+' {"number":"09868333140"} ,'+' {"number":"099-713-55036"}]}'; please declare it am getting Compile time Error @Zigma Commented Aug 26, 2014 at 4:28
  • compile time Error even i tried @this also but not working pleas help me in that Commented Aug 26, 2014 at 4:32
  • too many characters in character literal this Error actully coming Commented Aug 26, 2014 at 4:38
  • you need to learn something about how to use JSON in c#. After that you will understand what is the error. Commented Aug 26, 2014 at 4:40

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

1 Comment

can i have ur email id i need some IMP talk wid u

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.