ermm,
this is the situation,
i have a txt file, it contains

[
                    {
                        "cmdType":"G",
                        "row":0,
                        "col":2,
                        "ans":"心",
                        "cmd":"C",
                        "qNum":19
                    },
                    {
                        "cmdType":"G",
                        "row":1,
                        "col":1,
                        "ans":"心",
                        "cmd":"C"
                    }
]

i need to parse that and get one of the json object that inside that
json array and send that json object as string to client. the code
that i posted on the first post only works when there is no chinese
character in it.

this is the exception i get when it has chinese character in it.
Exception in thread "main" com.google.gson.JsonParseException: Failed
parsing JSON source: java.io.bufferedrea...@530daa to Json
        at com.google.gson.JsonParser.parse(JsonParser.java:57)
        at xwp.server.Test.main(Test.java:23)
Caused by: com.google.gson.TokenMgrError: Lexical error at line 1,
column 1.  Encountered: "\ufeff" (65279), after : ""
        at
com.google.gson.JsonParserJavaccTokenManager.getNextToken(JsonParserJavaccTokenManager.java:
1193)
        at com.google.gson.JsonParserJavacc.jj_ntk(JsonParserJavacc.java:635)
        at com.google.gson.JsonParserJavacc.parse(JsonParserJavacc.java:10)
        at com.google.gson.JsonParser.parse(JsonParser.java:54)
        ... 1 more

i would like to know how do i get this
                    {
                        "cmdType":"G",
                        "row":1,
                        "col":1,
                        "ans":"心",
                        "cmd":"C"
                    }

out of the json array and send it as string to client.

On Jul 16, 6:25 pm, Thomas Broyer <[email protected]> wrote:
> On 16 juil, 10:59, Alex <[email protected]> wrote:
>
> > yup im using the doGet method, but i need a parser to extract the json
> > object out of the json array (string). something like
> > JSONObject jsonObj=Parser.parse(some json array string).get(some
> > integer);
> > String resData=jsonObj.toString();
>
> > i just need some parser that can parse json that contains UTF-8 stuff.
>
> If the parser accepts a String (or Reader), then there's no character-
> encoding entering into play, so there's no "UTF-8 stuff". The "UTF-8
> stuff" is only when reading "bytes" into "characters".
>
> That being said, I don't have a solution to your problem (which you
> don't explicitly stated: you have an error, or a problem, but which
> one? what's the actual result? what's the expected result?), I can
> only say that the JSON parser probably isn't wrong.
> Also, make sure you send the result back to the client in UTF-8, i.e.
> on your HttpServletResponse, call setContentType("application/json;
> charset=UTF-8") before calling getWriter().

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to