Saturday, 7 January 2017

Json String to Key Value Pair in C#, Xamarin Android


Json String to Key Value Pair in C#, Xamarin Android

public static Dictionary<string, string> ParseJSONString(string s)
        {
            Regex reg = new Regex("\"(?<Key>[\\w]*)\":\"?(?<Value>([\\s\\w\\d\\.\\\\\\-/:_\\+]+(,[,\\s\\w\\d\\.\\\\\\-/:_\\+]*)?)*)\"?");
            MatchCollection matchCollection  = reg.Matches(s);

            Dictionary<string, string> json = new Dictionary<string, string>();

            foreach (Match kv in matchCollection)
            {
                json.Add(kv.Groups["Key"].Value, kv.Groups["Value"].Value);

            }
            return json;
        }

No comments:

Post a Comment