Skip to content

Instantly share code, notes, and snippets.

@MustafaFerhan
Last active November 4, 2021 06:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MustafaFerhan/25906d2be6ca109f61ce to your computer and use it in GitHub Desktop.
Save MustafaFerhan/25906d2be6ca109f61ce to your computer and use it in GitHub Desktop.
Webview evaluateJavascript JSON problem
import com.google.gson.JsonParser;
/**
* Created by mustafaferhan on 22/05/15.
*
* When the working on webview.evaluateJavascript() method, it return as String on onReceiveValue() method.
* The problem is this String not convertable for JSON Object.
* Error Log:
* org.json.JSONException: Expected literal value at character 1 of or
* JSONException: Value of type java.lang.String cannot be converted to JSONObject
*
* Gson method is simple and clear.
*
*/
public class StringUtil {
String getAsString (String param){
JsonParser parser = new JsonParser();
String retVal = parser.parse(param).getAsString();
return retVal;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment