Windows Phone mango development practices-gb2312 encoding conversion

Source: Internet
Author: User

The encoding Character Set supported by Windows Phone SDK 7.1 codenamed mango is UTF-8, UTF-16, UTF-16BE, and UTF-16LE, unfortunately there is no gb2312. When developing a Chinese Windows Phone application, we were confused about gb2312 character set in Web Services.

This article summarizes several gb2312 conversion methods. When you encounter similar problems, you don't have to worry about weekly network searches or questions. You just need to select a preferred method to solve them. In particular, I would like to thank you for sharing the third solution in the msdn forum ).

There are still some shortcomings in this article. Please give me some advice.

Method 1: gb2312 for Silverlight

The gb2312encoding class inherits the encoding abstract class and enables Silverlight (including Windows Phone) applications to support the gb2312 simplified Chinese character set.

The gb2312encoding class fully implements all encoding functions, so you can easily implement all character set encoding functions.

Code Example

 

WebClient _ WC = new WebClient ();

_ WC. Encoding = new gb2312.gb2312encoding ();

_ WC. downloadstringcompleted + = (SS, ee) => txtresult. Text = ee. result;

_ WC. downloadstringasync (New uri (txturl. Text ));

How to Use

Copy the gb2312encoding. CS and gb2312.bin files to your project andEnsure:

Gb2312.binFileBuild actionSet attribute to "embedded resource"

Gb2312.binThe file name is correct (this file name cannot be modified)

Gb2312encoding. CSAndGb2312.binThe file is in the same folder.

 

Http://gb2312.codeplex.com/

 

Method 2: encoding and decoding on the Web Service

Use other encoding classes provided by. Net framwork, such:System. Text. asciiencoding,System. Text. utf7encodingAndSystem. Text. utf32encodingTo perform the encoding and decoding operations on the web service.

Method 3 parse the XML file encoded in gb2312

The XML code is gb2312. When you use using (xmlreader reader = xmlreader. Create (streamresult) to read data, the system will prompt the error message: system does not support "gb2312 ". How can this problem be solved?

First, convert stream to string, and then read the XML Information.

VaR sr = new streamreader (streamresult );

String srresult = Sr. readtoend ();

Using (xmlreader reader = xmlreader. Create (New stringreader (srresult )))

{

Reader. readtofollowing ("encode ");

Encode = reader. readelementcontentasstring ();

 

Reader. readtofollowing ("decode ");

Decode = reader. readelementcontentasstring ();

}

 

 

Author:Cedar

Source: Http://www.cnblogs.com/highcedar

Sina Weibo: Http://weibo.com/highcedar

 

About Author:

Focus on the development of Windows azure and Windows Phone.

the copyright of this article is shared by the author and the blog site, for more information, see the source and author.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.