I retrieve data from mysql by php and save it as String
read= new BufferedReader(new InputStreamReader(s,"iso-8859-1"),8);
String line=null;
while ((line=read.readLine()) !=null)
{
text+=line+"\n";
}
output is
[{"DATE_OF_TEXT":"2015-05-06","total_rate_FORuser":"9.90000"},
{"DATE_OF_TEXT":"2015-05-30","total_rate_FORuser":"5.10000"}]
How parse JSON to my Javascript file in webview ?
To pass in the string after the page is loaded, you could use
String jsText = "javascript:addData('" + text + "');");
webView.loadUrl(jsText);
EDIT : In your case, modify the url with the string:
String urlWithData = yourUrl + "?data=" + text;
webView.loadUrl(urlWithData);
Then in the javascript, first get the text using window.location.search
var jsontext = window.location.search.substring(1).split('=')[1];
And then, convert the JSON text into a JavaScript object, using JSON.parse
var obj = JSON.parse(jsontext);
Related
I'm using amirdew/JSON library, which you can find here to parse my string to JSON.
The string I retrieved is this: https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=Portugal
This is the code I have at the moment, and it is not working and I believe that it is because of the keys...
public void ParseJson (String json){
JSON json2 = new JSON(json);
String firstTag = json2.key("query").key("pages").key("extract").stringValue();
txtInfo = findViewById(R.id.txtInfo);
txtInfo.setText(firstTag);
}
The firstTag variable is null because it can't retrieve any value. I want to retrieve the text inside "extracts". How can I do it? What keys do I need?
I suggest you to use the JSONObject which is already inside the SDK. You would use it like this:
String input = "..."; // your input
JSONObject obj = new JSONObject(input);
Strings extracts = obj.getJSONObject("query").getJSONObject("pages").getJSONObject("23033").getString("extract");
I have a google play store url "https://play.google.com/store/apps/details?id=com.apusapps.launcher&hl=en" from this url I have to store"com.example.launcher" in a seperate variable and compare from package name "com.example.launc" if compare I have to send a json request .how can I do that
Try this:
String s = "https://play.google.com/store/apps/details?id=com.apusapps.launcher&hl=en";
String s2 = s.substring(s.indexOf("=")+1, s.indexOf("&"));
Toast.makeText(this,"Milad: "+s2,Toast.LENGTH_LONG).show();
You can do like this:
String urlString = url.toString();
String finalString = urlString.substring(urlString.indexOf("=")+1,urlString.lastIndexOf("&"));
if(finalString.equals(getApplicationContext().getPackageName())){
//Your code
}
I am stuck at converting a Json string into query string.
Actually, I want to create query string and from that query string I'll generate a SHA hash and set it in header to send to the server.
Please help!
Is your JSON String currently stored in a JSONObject? If not, this would be the best place to start. Something like this:
JSONObject json = new JSONObject(returnedString);
String firstValue= json.get(firstKey);
String secondValue = json.get(secondKey);
//And then construct your query string using the obtained values
Edit
Generic Method as suggested below...
Something like this:
public String getQueryString(String unparsedString){
StringBuilder sb = new StringBuilder();
JSONObject json = new JSONObject(unparsedString);
Iterator<String> keys = json.keys();
sb.append("?"); //start of query args
while (keys.hasNext()) {
String key = keys.next();
sb.append(key);
sb.append("=");
sb.append(json.get(key);
sb.append("&"); //To allow for another argument.
}
return sb.toString();
If you have more questions regarding JSONObject parsing in Android these docs are very helpful
On Android :
Uri uri=Uri.parse(url_string);
uri.getQueryParameter("para1");
On Android, the Apache libraries provide a Query parser:
http://developer.android.com/reference/org/apache/http/client/utils/URLEncodedUtils.html and http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/utils/URLEncodedUtils.html
I have a html string in in which i am trying to get string between the tag using regexp and finally saving the value to array-list . But i am not able to get the string between the tag so my array-list is always empty.
<span><div style=\'float:left; width:350px;\'>Pharmacie DAR D\'BAGH</div>
my code to get the data using regexp is
private void findTextByRegExp()
{
ArrayList<ArrayList<String>>dataList1 = new ArrayList<ArrayList<String>>();
String pattern3 = "<span><div style=\'float:left; width:350px;\'>";
String pattern4 = "</div>";
String text = readFromFile();
Pattern p = Pattern.compile(Pattern.quote(pattern3) + "(.*?)" +
Pattern.quote(pattern4));
Matcher m = p.matcher(text);
while (m.find()) {
ArrayList<String>dataAdd = new ArrayList<String>();
dataAdd.add(m.group(1));
dataList1.add(dataAdd);
Log.d("Group data", "" + m.group(1));
}
Log.d("MY ARRAY LIST OD DATA", "" + dataList1);
}
please help me how to achieve this using regexp?
try
String pattern3 = "<span><div style=\\'float:left; width:350px;\\'>";
I have parse data from xml that contain html tag.
i am not able to get image src attribute can any one show this link.
http://mobileecommerce.site247365.com/admin/catdata.xml
i give you url it's not mean that i want to show whole code from you.i mean give some links or some idea for that.
Thanks in advance
Arpit
String str = "Your Cat_Desc tag value";
String[] temp;
if (str.contains("<img src=")) {
temp = str.split("<img src=");
String imagesUrl = temp[1].substring(
temp[1].indexOf("\""), temp[1]
.indexOf(" "));
imagesUrl = imagesUrl
.replace("\"", " ");
System.out.println("My image URL :: " +imagesUrl);
}else {
System.out.println("NO imageurl found"); }