crystalcoraldsouza / microsoft-translator-java-api

Automatically exported from code.google.com/p/microsoft-translator-java-api
0 stars 0 forks source link

Exception when text contains "\n" #11

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Translate text with \n
For example, "This is a test.\nThis is a test."

What is the expected output? What do you see instead?

java.lang.Exception: [microsoft-translator-api] Error retrieving translation.
    at com.memetix.mst.MicrosoftTranslatorAPI.retrieveStringArr(MicrosoftTranslatorAPI.java:220)
    at com.memetix.mst.translate.Translate.execute(Translate.java:101)
    at translator.BingTranslator.translate(BingTranslator.java:28)
    at translator.BingTranslator.main(BingTranslator.java:40)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to 
org.json.simple.JSONArray
    at com.memetix.mst.MicrosoftTranslatorAPI.jsonToStringArr(MicrosoftTranslatorAPI.java:273)
    at com.memetix.mst.MicrosoftTranslatorAPI.retrieveStringArr(MicrosoftTranslatorAPI.java:218)
    ... 3 more

What version of the product are you using? On what operating system?
0.6.2
windows 7

Please provide any additional information below.

Original issue reported on code.google.com by zxdd...@gmail.com on 27 Nov 2013 at 7:48

GoogleCodeExporter commented 8 years ago
Supplement:
This method Translate.execute()
If first parameter is String array, it will throw this exception.
If first parameter is String, it's ok.

Original comment by zxdd...@gmail.com on 27 Nov 2013 at 9:00

GoogleCodeExporter commented 8 years ago
In com.memetix.mst.MicrosoftTranslatorAPI abstract class buildStringArrayParam 
method, we have 
targetString.append(value);

Here if the value is appropriately escaped, then this problem could be solved. 
In my case, a double quote was causing the issue. When I tried with
targetString.append(value.replaceAll("\"", "\\\\\""));
it worked fine.

Original comment by srama...@gmail.com on 28 Feb 2014 at 6:28