OK: that isn't going to work - it isn't even going to compile.
string queryString = {"id": "1234", "name": "ABC XYZ", "given_name": "ABC", "family_name": "XYZ", "link": "http://profiles.google.com/123456", "gender": "male", "locale": "en-GB"};
will give you a huge pile of errors - the first being that you can only use an array initializer on an array. If you want to initialize this as a single string (and I assume you are for testing) then you need:
string queryString = "\"id\": \"1234\",...";
Where "..." is the rest of your string similarly handled. That will probably fix your main problem.
Then, your next problem is that your string contains both ':' as a delimiter, and ':' as a part of your string - look at the "http..." part.
If your string will always be of the form
"key":"value"
separated by commas, I would be tempted to use a Regex instead of manual processing:
public static Regex regex = new Regex("(?:\")(?<Key>.*?)(?:\")\\s*:\\s*(?:\")(?<Value>.*?)(?:\")",
RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
The MatchCollection for this should give you the groups you want.
"can you me the complete code . Try to give me perfect solution by mixing your code in my code. I got confused where should I use your code to get the desired result"
What did your last slave die of? :laugh:
public static Regex regex = new Regex("(?:\")(?<Key>.*?)(?:\")\\s*:\\s*(?:\")(?<Value>.*?)(?:\")",
RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);
...
string queryString = "\"id\": \"1234\", \"name\": \"ABC XYZ\", \"given_name\": \"ABC\", \"family_name\": \"XYZ\", \"link\": \"http://profiles.google.com/123456\", \"gender\": \"male\", \"locale\": \"en-GB\"";
MatchCollection matches = regex.Matches(queryString);
NameValueCollection queryParameters = new NameValueCollection();
foreach (Match match in matches)
{
queryParameters.Add(match.Groups["Key"].Value, match.Groups["Value"].Value);
}