Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
Posts: 10
Registered: ‎10-17-2013
My Device: Z30
My Carrier: Rogers

Encoding issue UTF8

I am passing updates to my app in a json format from a C sharp webservice.

 

I encode my text on the webservice side using "UTF8Encoding"

 

in my app i wait for file update reply

 

//catch reply
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
//put into byte array to loop through reply and grab only require reply block QByteArray buffer(reply->readAll()); //buffer only has &amp; still instead of & //Try and convert back from UTF8 to string and still &amp; instead of & QString DataAsString = QString::fromUtf8(buffer);

 

 The special characters are not getting picked up. Should the request be carried out in a different way or is the process wrong in this case?

 

Developer
Developer
Posts: 60
Registered: ‎04-14-2014
My Device: z10
My Carrier: Digitel

Re: Encoding issue UTF8

Are you absolutely sure that the process encoded to UTF-8 in C # fully meets the standard? It has happened that external to Qt functions not comply 100% with a standard and then cause problems.

My Answer is good? Nice! Please, Clicked the "Thanks" button, this is very helpful for me! Smiley Happy
Mi respuesta es buena? Que bien! Por favor, haz clic en el botón "Gracias", esto es muy útil para mí! Smiley Happy
Developer
Posts: 145
Registered: ‎12-23-2012
My Device: BB10 Dev Alpha
My Carrier: wifi

Re: Encoding issue UTF8

Looks like your data is url encoded, you can try to decode it

Developer
Posts: 45
Registered: ‎11-16-2013
My Device: Z10
My Carrier: AT&T

Re: Encoding issue UTF8

 

Add this in main.cpp

 

QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

 

Developer
Developer
Posts: 60
Registered: ‎04-14-2014
My Device: z10
My Carrier: Digitel

Re: Encoding issue UTF8

Sorry, but... What is this? I not understand. 

My Answer is good? Nice! Please, Clicked the "Thanks" button, this is very helpful for me! Smiley Happy
Mi respuesta es buena? Que bien! Por favor, haz clic en el botón "Gracias", esto es muy útil para mí! Smiley Happy
New Developer
Posts: 10
Registered: ‎10-17-2013
My Device: Z30
My Carrier: Rogers

Re: Encoding issue UTF8

[ Edited ]

Thanks for the replies. Have you got a link that says Blackberry native has issues with UTF-8 Encoding oGG?

 

 

My Web Request is as follows 

   [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

 public class Service1 : System.Web.Services.WebService
    {

[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string somemethod()
{
     FileStream jsonFile = getfile();

     byte[] b = new byte[jsonFile.Length];
     UTF8Encoding temp = new UTF8Encoding(true);

      while (jsonFile.Read(b, 0, b.Length) > 0)
      {
        message += temp.GetString(b);
      }
       jsonFile.Close();
       return message;
  }

etc...... }

 

 

My request comes into my app like the following

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/"> [{"Company":"/Black &amp; White London"/, etc....},{etc....

 

 

and again i catch it in the app like so

//catch reply
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

//put into byte array to loop through reply and grab only require reply block
QByteArray buffer(reply->readAll());

//buffer only has &amp; still instead of &
//Try and convert back from UTF8 to string and still &amp; instead of &
QString DataAsString = QString::fromUtf8(buffer);

 

 

Even with in the mapp.cpp i still end up with &amp; . Not sure if this is a api issue with blackberry as oGG said or just doing something wrong.

QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

 

 

Any links or ideas on this issue

 

Developer
Developer
Posts: 60
Registered: ‎04-14-2014
My Device: z10
My Carrier: Digitel

Re: Encoding issue UTF8

No, no Blackberry Native. Other platforms havent standars completely and generate problems with Blackberry Native. Sorry, my english suck very much. Smiley Frustrated
My Answer is good? Nice! Please, Clicked the "Thanks" button, this is very helpful for me! Smiley Happy
Mi respuesta es buena? Que bien! Por favor, haz clic en el botón "Gracias", esto es muy útil para mí! Smiley Happy
Highlighted
New Developer
Posts: 10
Registered: ‎10-17-2013
My Device: Z30
My Carrier: Rogers

Re: Encoding issue UTF8

Thanks for the reply oGG. Has anyone any ideas on how to program around this. I presume other people have come across this issue and have found a work around. I dont think people are using webservices and not being able to re generate text in their app containing special characters.