Box characters within JSON response - java

This is my JSON String which is generated using Java:
[{\"userFirstNm\":\"Tamás\",\"userAsscId\":\"37732\",\"userLastNm\":\"Török\",\"userLanId\":\"a37732\"}]
Using an alert in JavaScript displays boxes inside string and breaks my eval function.
Please find details in attached screen shot.
alt text http://www.freeimagehosting.net/uploads/336da972f3.png

its invalid json
try this.
[{"userFirstNm":"Tamás","userAsscId":"37732","userLastNm":"Török","userLanId":"a37732"}]

Related

Couldn't get text from a text field using selenium

I am trying to get value from a text field using selenium, but I am not able to. The value is neither present between the tags nor in the attribute "value".Please help me with this.
I have tried following ways but nothing worked.
Webelement.getAttribute("innerText");
Webelement.gettext();
Webelement.getAttribute("value");
Webelement.getAttribute("textcontent");
Below is the HTML for the text field.
<input name="quantityField_valueFieldKeyboard" id="quantityField_valueFieldKeyboard" data-mini="true" data-clear-btn="false" maxlength="61" seyctype="numeric" class="seyc-visually-important seyc-ui-input-icon-white seyc-ui-input-text">
is this what you are trying?
driver.findElement(By.id("quantityField_valueFieldKeyboard")).getAttribute("value");
driver.findElement(By.id("quantityField_valueFieldKeyboard")).getAttribute("value");
is correct way. You are getting empty string is also correct because your text field has no data in it. Since this is an input field, first enter some text and once text is saved. Try to fetch the entered text you will get your desired results.

converting HTML to String without TextView

I am having Problems filling my TextView.
I have an HTML String that needs to be converted from HTML to String and the replace some characters.
Problem is: I can convert it directly with:
TextView.setText(Html.fromHtml(sampleText);
But I need to alter the converted sampleText before giving it to the TextView.
E.g.:
String sampleText = "<b>Some Text</b>"
newSampleText = Html.fromHtml(sampleText);
newSampleText.replace(char1, char2);
TextView.setText(newSampletext);
Does anyone know how to convert the HTML saved inside the String?
if you don't need formatting, use Html.fromHtml(sampleText).toString()
otherwise, you need to extract text from html with jsoup to find and change text like here
please try this one:
You need to use Html.fromHtml() to use HTML in your XML Strings. Simply referencing a String with HTML in your layout XML will not work.
DEMO
Try use This version of setText and use SPANNABLE buffer type
DEMO1

GWT HTML not showing line breaks

I'm trying to display a GWT UiField HTML object with line breaks, but it doesn't seem to work.
I accept a string, sanitize it using the SimpleHtmlSanitizer, and then the line breaks display as text instead of html in the AlertWidget, which is a DialogBox.
#UiField
HTML description;
public AlertWidget(String htmlMessage) {
SafeHtml safeMessage = SimpleHtmlSanitizer.sanitizeHtml(htmlMessage);
setWidget(uiBinder.createAndBindUi(this));
this.description.setHTML(safeMessage);
}
On the page, the contents of the dialog box end up looking exactly like the input String:
The first error<br>the second error
I can see in my ide that the sanitized SafeHtml contains the safe value:
The first error<br>the second error
Take a look at the documentation for sanitizeHtml. At the top there's a list of supported tags. The break line tag is not supported.
I'd try some other mechanism for creating the SafeHTML:
http://www.gwtproject.org/javadoc/latest/com/google/gwt/safehtml/shared/SafeHtmlBuilder.html

How to get url from JSON text

Wondering if it is possible to get url's from the text, wich I parse from JSON. For example I have some JSON object which is in the JSON array and called "text". This "text" contains strings and images (url's) like a img src=\u0022http:\/\/www.dostup1.ru\/netcat_files\/Image\/2014\/08\/04\/dzd-2.jpg
but "img" or "src" are not in quotation marks so how can I get them and then parse this images to show?
item.setContent(post.getString("text"));
This is how I parse text and when it loads, it show me text with strange green rectangles instead of images (because of method doesn't know about how to parse image from url which just is in the text)
Lets assume that you have this piece of String from the result of your JSON.
<img src="http:\/\/www.dostup1.ru\/netcat_files\/Image\/2014\/08\/04\/dzd-2.jpg">
Then you just need to use the split method of the String class to extract the url between qoutes.
sample:
This is just a sample java program that split the URL from the JSON response you got
String s = "<img src=\"http://www.dostup1.ru/netcat_files/Image/2014/08/04/dzd-2.jpg\">";
String [] result = s.split("\"");
System.out.println(result[1]);
result:
http://www.dostup1.ru/netcat_files/Image/2014/08/04/dzd-2.jpg

Get content from javascript onClick hyperlink

I'm trying to get the content from a website, that uses "onClick" instead of "href" in hyperlinks, so the url is always the same, despite of the page you are seeing.
http://www.sas.ul.pt/index.php
This is the website, and the content i'm trying to get is inside "Alimentação" > "Estudantes".
Estudantes
Is this possible with Jsoup?
Jsoup.connect(url).data("nav", "index#4;02", "opt", "4;02", "chvP", "127").post();
You can get the value of onclick with jsoup
http://jsoup.org/cookbook/extracting-data/attributes-text-html
Just replace the line
String linkHref = link.attr("href");
with this
String handler = link.attr("onclick");
However after that there is no way to construct the URL unless you can somehow map the magic number to 4,02

Categories

Resources