PDA

View Full Version : [CLOSED] How do I recover my original string, with accents?



supera
Jan 25, 2012, 11:08 AM
Hi

In my gridPanel, the directEvent SelectionChange call my procedure SelectionChanged, passing to the procedure the values of selected row, as follow:



<DirectEvents>
<SelectionChange OnEvent="lstAgendasSalasSGE_SelectionChanged"
Failure="Ext.MessageBox.alert('Load failed', 'Error during ajax event!');">
<ExtraParams>
<ext:Parameter Name="values" Value="Ext.encode(#{lstAgendasSalasSGE}.getRowsValues({se lectedOnly:true}))" Mode="Raw" Encode="true" />
</ExtraParams>
</SelectionChange>
</DirectEvents>


the values that I get in my procedure are serialized in Json, as follow...


""[{\"IDAgendaSala\":3,\"Descricao\":\"Sala Igua\\u00e7u\",\"Detalhes\":\"\"}]""

note that the value of Description modelfield are with a code instead of ç (c cedilha, character widely used in Brazil)...
Is thus: Sala Igua\\u00e7u
and should be as follows: Sala Iguaçu

this happens with all my accented characters

I try deserialize the Json string with this code



Ext.Net.JSON.Deserialize(JsonString.Trim)


Am I doing something wrong? I´m missing some step?

Thanks for any help.

Vladimir
Jan 25, 2012, 11:23 AM
Hi,


Deserialization process doesn't decode unicode escape symbols


Try to pass deserialized string through the following function


public string DecodeUnicodeCharacters( string value ) {
return Regex.Replace(
value,
@"\\u(?<Value>[a-zA-Z0-9]{4})",
m => {
return ((char) int.Parse( m.Groups["Value"].Value, NumberStyles.HexNumber )).ToString();
} );
}

Daniil
Jan 25, 2012, 11:28 AM
Hi,

Please remove one encoding:


Ext.encode()
or

Encode="true"

There is

Ext.encode(Ext.encode());

I guess it should solve the problem.

supera
Jan 25, 2012, 12:08 PM
Ok, Thanks...

Removing the tag
Encode, worked...

I had created the role suggested by Vladimir, in VB ... follows, if it is useful to someone



Public Shared Function DecodeUnicodeCharacteres(v As String) As String
'tenho que percorrer a string, e onde encontrar \u, pegar os 4 próximos cararectres (que estão em hexadecimal) e converter o valor deles para toString
Dim vPos As Integer

vPos = InStr(1, v, "\u")
Do While vPos <> 0
v = v.Replace(Mid(v, vPos, 6), Chr(Integer.Parse(Mid(v, vPos + 2, 4), Globalization.NumberStyles.HexNumber)))
vPos = InStr(1, v, "\u")
Loop

Return v

End Function