public void FromJSON(String JSON) { json_mem = JSON; JSON = JSON.Replace("\n", "").Trim(); Match m; //status m = new Regex("\\\"status\\\"\\:([0-9]*),", RegexOptions.IgnoreCase).Match(JSON); status = Int32.Parse(m.Groups[1].Value); //------- //ID m = new Regex("\\\"id\\\"\\:\\\"([^\\\"]*)\\\",", RegexOptions.IgnoreCase).Match(JSON); ID = m.Groups[1].Value; //------- //hypotheses int l1 = JSON.IndexOf("hypotheses"); l1 = JSON.IndexOf("[", l1); int r1 = JSON.LastIndexOf("]"); string JSON2 = JSON.Substring(l1, r1 - l1 + 1); MatchCollection m2 = new Regex("{([^\\}]*)}", RegexOptions.IgnoreCase).Matches(JSON2); foreach (Match g in m2) { string s = g.Value; SpeechInputResult.Hypothesis h = new SpeechInputResult.Hypothesis(); m = new Regex("\\\"utterance\\\"\\:\\\"([^\\\"]*)\\\"", RegexOptions.IgnoreCase).Match(s); h.utterance = m.Groups[1].Value; m = new Regex("\\\"confidence\\\"\\:([0-9\\.]*)", RegexOptions.IgnoreCase).Match(s); string confidence = m.Groups[1].Value; confidence = confidence.Replace(".", ","); if (confidence != "") { h.confidence = float.Parse(confidence); } hypotheses.Add(h); } //------- }
public void FromJSON(String JSON) { json_mem = JSON; JSON = JSON.Replace("\n","").Trim(); Match m; //status m = new Regex("\\\"status\\\"\\:([0-9]*),", RegexOptions.IgnoreCase).Match(JSON); status = Int32.Parse(m.Groups[1].Value); //------- //ID m = new Regex("\\\"id\\\"\\:\\\"([^\\\"]*)\\\",", RegexOptions.IgnoreCase).Match(JSON); ID = m.Groups[1].Value; //------- //hypotheses int l1 = JSON.IndexOf("hypotheses"); l1 = JSON.IndexOf("[",l1); int r1 = JSON.LastIndexOf("]"); string JSON2 = JSON.Substring(l1, r1-l1+1); MatchCollection m2 = new Regex("{([^\\}]*)}", RegexOptions.IgnoreCase).Matches(JSON2); foreach (Match g in m2) { string s = g.Value; SpeechInputResult.Hypothesis h = new SpeechInputResult.Hypothesis(); m = new Regex("\\\"utterance\\\"\\:\\\"([^\\\"]*)\\\"", RegexOptions.IgnoreCase).Match(s); h.utterance = m.Groups[1].Value; m = new Regex("\\\"confidence\\\"\\:([0-9\\.]*)", RegexOptions.IgnoreCase).Match(s); string confidence = m.Groups[1].Value; confidence = confidence.Replace(".", ","); if (confidence != "") { h.confidence = float.Parse(confidence); } hypotheses.Add(h); } //------- }