2012-09-24 3 views
1

WP7의 인코딩 문제가 있습니다. API에 json 요청을 보내면 응답에 독일어 움라우트가 포함되지만 어떤 이유로 인해 잘못 표시됩니다. 즉, 코드는 요청을 만들기위한이다 :WP7 Umlauts 및 특수 문자

public static void makeRequest(string requestString,List<String> parameters,Action<string> handleRequestResult) 
    { 
     //generate a random nonce and a timestamp 
     Random rand = new Random(); 
     Random rand2 = new Random(); 
     string nonce1 = rand.Next().ToString(); 
     string nonce2 = rand2.Next().ToString(); 
     string nonce = nonce1 + nonce2; 
     string timestamp = GetTimestamp(); 

     //create the parameter string in alphabetical order 
     //string parameters = "oauth_callback=" + UrlHelper.Encode("http://www.example.com"); 
     parameters.Add("oauth_consumer_key=" + ConsumerKey); 
     parameters.Add("oauth_nonce=" + nonce); 
     parameters.Add("oauth_signature_method=HMAC-SHA1"); 
     parameters.Add("oauth_timestamp=" + timestamp); 
     parameters.Add("oauth_version=1.0"); 

     //sorting the list of parameters (adding '&' between them) 
     string sortedParameters = sortParams(parameters); 

     //generate a signature base on the current requeststring and parameters and adding it to request string 
     string signature = generateSignature("GET", requestString, sortedParameters); 
     string url = requestString + "?" + sortedParameters + "&oauth_signature=" + signature; 

     //test the request 
     WebClient web2 = new WebClient(); 
     web2.Encoding = UTF8Encoding.UTF8; 
     //string result = web.DownloadString(url); 
     web2.DownloadStringCompleted += (sender, e) => 
     { 
      string result = (string)e.Result; 
      handleRequestResult(result); 


      //App.ViewModel.LoadData(result); 
     }; 
     web2.DownloadStringAsync(new Uri(url)); 
    } 

을 그리고 여기에 뷰에 대한 응답을로드하는 예제 코드입니다 : 기본적으로 enter image description here

: 내가 얻을 결과입니다

public void LoadBlogPosts(string content) 
    { 

     if (!AddToExistingBlogs) 
     { 
      this.BlogPosts.Clear(); 
     } 


     XDocument xml = XDocument.Parse(content); 
     foreach (XElement element in xml.Descendants("item")) 
     { 
      BlogViewModel newBlog = new BlogViewModel(); 
      newBlog.Title = element.Element("title").Value; 
      newBlog.Description = element.Element("description").Value; 
      newBlog.Link = element.Element("link").Value; 
      newBlog.Category = element.Element("category").Value; 
      //newBlog.Comments = element.Element("comments").Value; 
      newBlog.PubDate = element.Element("pubDate").Value; 
      XNamespace dc = "http://purl.org/dc/elements/1.1/"; 
      XNamespace wfw = "http://wellformedweb.org/CommentAPI/"; 
      XNamespace atom = "http://www.w3.org/2005/Atom"; 
      XNamespace sy = "http://purl.org/rss/1.0/modules/syndication/"; 
      XNamespace slash = "http://purl.org/rss/1.0/modules/slash/"; 
      XNamespace contentn = "http://purl.org/rss/1.0/modules/content/"; 
      newBlog.Dccreator = element.Element(dc + "creator").Value; 
      newBlog.Guid = element.Element("guid").Value; 
      newBlog.WfwCommentRss = element.Element(wfw + "commentRss").Value; 
      newBlog.SlashComments = element.Element(slash + "comments").Value; 
      newBlog.Content = "<html><body style='color: white; background-color:Black'>"; 
      newBlog.Content += element.Element(contentn + "encoded").Value; 
      newBlog.Content += "</body></html>"; 

      // 
      //Extract images from post: 
      // 
      // Size the control to fill the form with a margin 

      var reg = new Regex("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?"); 
      var match = reg.Match(newBlog.Content); 
      if (match.Success) 
      { 
       newBlog.FeaturedImage = match.Groups["imgSrc"].Value; 
      } 
      else 
      { 
       newBlog.FeaturedImage = @"http://karkur.com/no_image.png"; 
      } 



      BlogPosts.Add(newBlog); 

     } 

    } 

WP7에서 유니 코드 문자를 이스케이프 처리해야하는 것은 다음과 같습니다. enter image description here

일반 문자

답변

0

인코딩을 ISO-8859-1로 설정해야합니다. 그래서, 당신의 경우 :

web2.Encoding = Encoding.GetEncoding("ISO-8859-1"); 
+0

고맙지 만 그것은 아무 것도 바뀌지 않았습니다! –

+0

휴대 전화의 언어 설정이 독일어로 설정되어 있습니까? –

+0

문제가되지 않아도 XML로 응답 할 때 독일어로 표시되므로 문제는 없습니다. –