示例#1
0
        public static string getTranslateFromNaverAPI(string text)
        {
            var jsonResponseRaw = WebRequester.getResponseTranslateAPI(getDetectedLanguage(text), text);

            try
            {
                JObject jsonResponse = JObject.Parse(jsonResponseRaw);

                string result = (string)jsonResponse["message"]["result"]["translatedText"];

                return(result);
            }
            catch (Exception e)
            {
                return($@"죄송합니다. {jsonResponseRaw} 에러가 터졌네요. 여길 가서 확인해보세요 -> https://developers.naver.com/docs/common/common_error/");
            }
        }
示例#2
0
        public static List <KeyValuePair <string, string> > getInfoFromNaverAPI(string queryWord, int currentDisplayCount)
        {
            var jsonResponseRaw = WebRequester.getResponseSearchAPI(queryWord, 5, currentDisplayCount);

            try
            {
                JObject jsonResponse = JObject.Parse(jsonResponseRaw);

                var result = new List <KeyValuePair <string, string> >();

                int idx = currentDisplayCount;
                foreach (var i in jsonResponse["items"])
                {
                    string description = HttpUtility.HtmlDecode((string)i["description"]);
                    description = Regex.Replace(description, "<.*?>", string.Empty);

                    string title = HttpUtility.HtmlDecode((string)i["title"]);
                    title = Regex.Replace(title, "<.*?>", string.Empty);

                    var pair = new KeyValuePair <string, string>($"{idx++}. {title} : {description}\r\n", (string)i["link"]);

                    result.Add(pair);
                }

                if (result.Count == 0)
                {
                    return(new List <KeyValuePair <string, string> > {
                        new KeyValuePair <string, string>($"There are no {queryWord}", $"www.google.com/#q={queryWord}")
                    });
                }

                return(result);
            }
            catch (Exception e)
            {
                return(new List <KeyValuePair <string, string> > {
                    new KeyValuePair <string, string>(jsonResponseRaw, @"https://developers.naver.com/docs/common/common_error/")
                });
            }
        }