Re: [go-nuts] Converting escaped unicode to utf8

2023-02-02 Thread Ben Song
strconv.Unquote returns invalid syntax if the string contains `"`. It is better to quote string before Unquote. https://go.dev/play/p/ndfEi9tSjaM On Thursday, December 29, 2016 at 7:44:07 AM UTC+8 Jakob Borg wrote: Both json.Unmarshal and strconv.Unquote seem to handle this fine: https://play.

Re: [go-nuts] Converting escaped unicode to utf8

2016-12-28 Thread Jakob Borg
Both json.Unmarshal and strconv.Unquote seem to handle this fine: https://play.golang.org/p/mexmJNGQyh //jb > On 28 Dec 2016, at 15:03, JohnGB wrote: > > I tried this with a variety of messages, and it doesn't work with most > unicode escaped string. For example, the unicode escaped string

Re: [go-nuts] Converting escaped unicode to utf8

2016-12-28 Thread JohnGB
My response should have read that it produces an error of "invalid character 'Ñ' looking for beginning of value". I got the responses from the two methods mixed up. On Monday, 26 December 2016 17:32:56 UTC+1, rog wrote: > > On 26 December 2016 at 07:23, JohnGB > > wrote: > > It *should* have

Re: [go-nuts] Converting escaped unicode to utf8

2016-12-28 Thread JohnGB
I tried this with a variety of messages, and it doesn't work with most unicode escaped string. For example, the unicode escaped string '\u044d\u0442\u043e \u0442\u0435\u0441\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435' should unescape to 'это тест сообщение' but it unescapes t

Re: [go-nuts] Converting escaped unicode to utf8

2016-12-28 Thread JohnGB
I tried this with a variety of messages, and it doesn't work with most unicode escaped string. For example, the unicode escaped string '\u044d\u0442\u043e \u0442\u0435\u0441\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435' should unescape to 'это тест сообщение' but it unescapes t

Re: [go-nuts] Converting escaped unicode to utf8

2016-12-28 Thread JohnGB
That look like a nice solution. I'll have to benchmark the methods and see which one wins out in the end. On Monday, 26 December 2016 19:34:16 UTC+1, C Banning wrote: > > If you're processing anonymous messages and don't know where unicode will > occur you might want something like this: > htt

Re: [go-nuts] Converting escaped unicode to utf8

2016-12-26 Thread C Banning
If you're processing anonymous messages and don't know where unicode will occur you might want something like this: https://play.golang.org/p/M-21sy_en5 On Monday, December 26, 2016 at 9:41:15 AM UTC-7, JohnGB wrote: > > Thanks Roger. That is a really elegant solution. > > On 26 December 2016 a

Re: [go-nuts] Converting escaped unicode to utf8

2016-12-26 Thread John Beckett
Thanks Roger. That is a really elegant solution. On 26 December 2016 at 17:32, roger peppe wrote: > On 26 December 2016 at 07:23, JohnGB wrote: > > It *should* have a JSON body, but in this particular case I can't be sure > > that it will, as I'm trying to log requests when there are errors, w

Re: [go-nuts] Converting escaped unicode to utf8

2016-12-26 Thread roger peppe
On 26 December 2016 at 07:23, JohnGB wrote: > It *should* have a JSON body, but in this particular case I can't be sure > that it will, as I'm trying to log requests when there are errors, which are > quite often errors in the request. So although in some cases it is decoded > later in the handle

Re: [go-nuts] Converting escaped unicode to utf8

2016-12-25 Thread JohnGB
It *should* have a JSON body, but in this particular case I can't be sure that it will, as I'm trying to log requests when there are errors, which are quite often errors in the request. So although in some cases it is decoded later in the handler chain, I need to be able to log the string in a

Re: [go-nuts] Converting escaped unicode to utf8

2016-12-24 Thread Matt Harden
If it has a JSON body, are you using encoding/json to parse / decode it? That will handle the unescaping for you. On Sat, Dec 24, 2016 at 4:54 PM JohnGB wrote: > I have an application where I am processing a HTTP request with a JSON > body. However, the JSON in the body has been unicode escaped