Hello
I am in trouble to separate the required data from the string array
this code is working fine
public void show_data()
{
string queryString = "email=abc@abc.com&isVerified=true";
NameValueCollection nvc = StringToNameValueCollection(responseText);
if (nvc["email"] != "")
{
userName = nvc["email"].ToString();
}
}
NameValueCollection StringToNameValueCollection(string queryString)
{
NameValueCollection queryParameters = new NameValueCollection();
string[] querySegments = queryString.Split('&');
foreach (string segment in querySegments)
{
string[] parts = segment.Split('=');
if (parts.Length > 0)
{
string key = parts[0].Trim(new char[] { '?', ' ' });
string val = parts[1].Trim();
queryParameters.Add(key, val);
}
}
return queryParameters;
}
but when i modified the code
public void show_data()
{
string queryString = {"id": "1234", "name": "ABC XYZ", "given_name": "ABC", "family_name": "XYZ", "link": "http://profiles.google.com/123456", "gender": "male", "locale": "en-GB"};
NameValueCollection nvc = StringToNameValueCollection(responseText);
if (nvc["email"] != "")
{
userName = nvc["email"].ToString();
}
}
NameValueCollection StringToNameValueCollection(string queryString)
{
NameValueCollection queryParameters = new NameValueCollection();
string[] querySegments = queryString.Split(',');
foreach (string segment in querySegments)
{
string[] parts = segment.Split(':');
if (parts.Length > 0)
{
string key = parts[0].Trim(new char[] { '?', ' ' });
string val = parts[1].Trim();
Response.Write(key + ":" + val);
queryParameters.Add(key, val);
}
}
return queryParameters;
}
here queryparameters returns the output like this
{"id":"1234" "name":"ABC XYZ" "given_name":"ABC" "family_name":"XYZ" "link":"http "gender":"male" "locale":"en-GB"}
Here i want to also reduce the all the double quotes(")
i want solution to gid rid of the double qoutes(")
thanks,
Deepak
[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]