Bold words in a string of json file in Android
JSON only stores plain text, It does not format the text, if you want to make the data in the JSON object appear bold or colorful in the UI you need to handle this from the front end side.
Can a json string contain HTML tags with it?
Technically, yes, you can do that... practically, I'd be a bit concerned if there were HTML markup in my data. What else might be in there? Smells like an XSS vulnerability.
Bold Specific Elements from JSON Array in Rich Textbox
You need to use AppendText
. When you use Text+= "something"
you replace the format.
You can use this example:
var json = "{\"Title\":\"This is a Title\", \"Content_One\": \"This is alittle informative paragraph based on the subject selected\", \"Title_Two\": \"This is another paragraph\"}";
var start = 0;
Dictionary<string, string> values = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(json);
values.Cast<KeyValuePair<string, string>>()
.ToList()
.ForEach(item =>
{
this.richTextBox1.AppendText(item.Key);
this.richTextBox1.AppendText( ":" );
start += item.Key.Length + 1;
this.richTextBox1.AppendText(item.Value);
this.richTextBox1.Select(start, item.Value.Length);
this.richTextBox1.SelectionFont = new Font(this.richTextBox1.Font, FontStyle.Bold);
this.richTextBox1.AppendText("\n");
start += item.Value.Length + 1;
});
Screenshot:
Related Topics
Multiply and Sum Input Values Created Dynamically in Jquery
How to Loop Over Object Properties With Ngfor in Angular
How to Remove Image from Browser Cache
Calculate String Value in Javascript, Not Using Eval
Vuejs Accessing a Method from Another Method
How to Create Prompt With Two Input Fields
How to Intercept Button Click Inside Uiwebview on Ios
How to Add and Remove Class to Menu Items on Mouseover
How to Hide Code from Cells in Ipython Notebook Visualized With Nbviewer
Set Some Specific Options in Multiselect as Disabled and Selected
How to Avoid Scientific Notation for Large Numbers in JavaScript
Pull Variable Value from JavaScript Source Using Beautifulsoup4 Python
Switch Fontawesome Icon on Click, Not Working
Automatically Refreshing Page Every 60 Seconds Using JavaScript
Node Server Running But Localhost Refusing to Connect
Get Weeks in Month Through JavaScript
How to Hide the Android Keyboard Using JavaScript
Check Whether Elements from One Array Are Present in Another Array