×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    5

    Reading in UTF-8 HTTP Response - Device Problem

    My java program is reading from a web page a simple line of UTF-8 encoded characters (Chinese and Latin). My problem is that on the Nokia Series 40 emulator I am successfully able to read the characters and display on the screen (in Chinese), but on a real device i get boxes instead of characters (somewhat like: []). I am sure my device can display Chinese characters appropriately when they are hardcoded in the midlet, but can't draw out when i read from a web page.

    The code I am using to read in the characters is:
    Code:
    StringBuffer data = new StringBuffer();
    try
    {
        strConn = (StreamConnection)Connector.open(server + "/" + message);
        System.out.println(server + "/" + message);
        in = strConn.openInputStream();  		
        InputStreamReader isr = new InputStreamReader(in,"UTF-8");      
    
        int ch;
        boolean done = false;
        while ((ch = isr.read()) > -1) {
              data.append((char)ch);
        }
    
    String[] response = myValues(data.toString()); // my function
    return response;
    }
    Thanks for any help. I've been digging through the messageboard but have had no luck with this situation. Any help is greatly appreciated!!!

  2. #2
    Registered User
    Join Date
    Dec 2004
    Posts
    5

    Isolated the problem...

    Ok, I've isolated the problem to reading the characters off of the server. Each character getting read in has an integer value of 65533 which is why i'm seeing those square boxes. The strangest part is that the emulator can decode the server perfectly, but the device sees the character as a 65533 value.

    I've tested it with a file for the InputStream and its decoding OK, so I'm guessing it has to do with the servers encoding, or the phone can't tell over a StreamConnection to a server that its UTF8 and not text? Not really sure, again any help is appreciated!

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×