what did richfaces do to javascript JSON? - json

I want to use JSON.stringify() to convert my JS object to a json string. But when I use richfaces components in the web page, I got the wrong result. See the example below. Please help me. Thank you!
this is the codes:
function testJSON()
{
var selArray = new Array();
selArray.push("aaa");
selArray.push("bbb");
selArray.push("ccc");
alert(JSON.stringify(selArray));
}
I got this if there is no richfaces components in the page.
["aaa","bbb","ccc"]
And if there is any richfaces component like "rich:modalpanel" in the page, it will get the following wrong JSON string.
"[\"aaa\",\"bbb\",\"ccc\"]"
I think that's because richfaces has done songthing that affected JSON.
So what can I do to avoid the effect of richfaces ?
Thank you very much!

Perhaps you are running into this issue, since Richfaces uses Prototype: JSON.stringify() array bizarreness with Prototype.js
I was able to fix the problem with one of the answers: https://stackoverflow.com/a/6611126/132374

Related

How to convert HTML to JSON correctly?

I am having trouble with this in Flutter / Dart.
Currently, I am trying to fetch the data.
someHTML = parse(json["somed"]).documentElement!.text;
JSON:
{"somed":"<h2>Thing<\/h2>\n<h1>Interesting<\/h1>\n<p>Expiring<\/p>\n"}
But whatever I do, I can't fetch this properly. If I do:
{"somed":"Test"}
So, plain text - it works! However, with HTML like H2, I can't get it to work (just throws empty). The HTML I am trying to fetch is from a website and I am trying to get that data.
Anyone who can help here? I tried innerHTML, outerHTML etcetera, but I can't solve it.
Solved it myself. Adding ?? "" did the trick!
someHTML = parse(json["somed"] ?? "").documentElement!.text;

Using Razor.Engine.NetCore in rest api solution .net core 3.1 with Url.Encode

I'm trying to use Razor.Engine outside of MVC, everything works good, but now I need to encode url inside Razor template.
My template is:
<html>
<p><span>Click here</span></p>
</html>
My Model is:
BaseUrl = "http://mysiteurl",
UrlParams = "{"id":"43869906-dfdb-435c-a570-c4578d859e78"}"
I need to encode the UrlParams so I tried
href="#Model.BaseUrl?data=#Url.Encode(#Model.UrlParams)"
But no luck :(
Is it possible to encode url inside Razor template? and how?
I could not find the ability to add namespaces
I Also tried with RazorEngineService.create(config).RunCompile(...) but still not working
Thanks
So I ended up with this
#Model.BaseUrl?data=#System.Net.WebUtility.UrlEncode(#Model.UrlParams.ToString())
and it's working :)

How to populate a jquery grid using Knockout JS in MVC 4

I'm new to ASP.NET MVC and Knockout JS. I have a project requirement as below.
I should have a List<> in a ViewModel which is the data for my grid.
I need to pass that List's data from the Controller to the
view through a $.ajax() method.
The data coming from the controller should be in JSON format.
I should use Knockout JS for data-binding in my view.
Please, can anybody help me to do this task with an example or provide me some web links for the demo.
About returning JSON, ASP.Net WebAPI should be you best bet. Some samples here : http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
KO Grid could help you doing that on the front-end side. There's some sample here to get you started : http://knockout-contrib.github.io/KoGrid/#/overview
I think that's actually the only things you'll need to get you started!

JSON output in Umbraco 5

I just switched from Umbraco 4 to Umbraco 5 and it seems like a lot has changed.
So what i basically want is a possibility to add a alternative template to my document-types.
The fall back template shall return the content as JSON.
Why, you say? I want to create an API-like way of accessing the Umbraco data from my mobile devices.
WebAPI (http://cultiv.nl/blog/2012/4/22/exposing-umbraco-5-content-through-the-aspnet-web-api/)
I have thought about using WebAPI from asp.net MVC 4, but the project is really just a proof of concept and i don't want to code each endpoint.
So i found a som guys that did a package for Umbraco 4 that actually does this and renders the content of #currentPage as Json. The template is hit by adding "/JSON" to the end of the url. Unfortunetly this uses xslt, which ihas been removed from Ubraco 5.1 (Good thing).
So. I bet it's simple to create a partial, a macro or a partial macro that does this and add it to a template. But is just cant figure out where to start.
Any help with that? What I'm looking for is a step guide on what steps to take, to make the setup. Rendering the stuff ad json in C# i can handle.
It's the integration into Umbraci I lack.
Hoe u can help.
The alternative templating works exactly like in v4: Just add the name of the template at the end of the url: yoururl/json
Then add a new razor view to the templates named "json" with the following code:
#inherits RenderViewPage
#using System.Web.Mvc.Html;
#using Umbraco.Cms.Web;
#{
Layout = "";
}
{
#foreach (var attribute in Model.Attributes)
{
string.Format("\"{0}\": \"{1}\"", attribute.AttributeDefinition.Alias, attribute.DynamicValue);
}
}
This code can be used as a starting point without using the web api or own controllers.
Don't forget to allow the tempplate on all document types
hth,
Thomas

How to parse JSON in PhoneGap?

I am implementing a mobile application using PhoneGap framework. I don't know how to parse JSON in PhoneGap.
Can you advise me for that?
This is more a JavaScript than a PhoneGap question.
It should be safe to use JSON.parse(myJsonString) since no old browsers are going to be used with PhoneGap.
Phonegap let´s you call to device functions like gps with a simple javascript interface.
To parse a JSON object you can try this two ways:
Clean example,
first, include jquery, will be more easy
make a button with id = "searchButton", a div with id="dataParsed" and a textbox with id="searchBox"
include this code:
$('#searchButton').click(function() {
$.getJSON('http://api.alternativeto.net/software/'+$('#searchBox').val()+'/?count=15',
function(data) {
var items=data.Items;
// uncomment the line to see the structure of the json
//console.log(items);
var list = $('#dataParsed');
list.html("");
$.each(items, function(key, val) {
list.append($(document.createElement('p')).html(val.Name));
});
});
});
Example of json+ajax+ jquerymobile: Read this in the phonegap wiki:
http://wiki.phonegap.com/w/page/36868306/UI%20Development%20using%20jQueryMobile
Good Luck! :)
actually I think you are little confused, phonegap doesn't let you parse json, you parse json with javascript (like crokford json parser library or jquery json parsing methods) the only thing phonegap does is expose the native api of various mobile operation systems to a common javascript interface.
You can use 2 methods for parsing JSON Data
var parsedData = $.parseJSON(yourJSONdata);
var parsedData = JSON.parse(yourJSONdata);