dnagir ha scritto:
The type of the data is always string. I also cannot specify the
dataType. If it will be different (HTML instead of JSON) jQuery fails
silently.
[...]
Unfortunately I do not see jQuery providing similar function, while
Prototype does:
http://www.prototypejs.org/api/string/isJSON
Don't know how prototype implement this, and don't know if exists a
better way, but it works:
function isJson(string) {
return typeof(eval("(" + string + ")")) == 'object';
}
stringjson = '{"type": "menu","value": "File","items": [{"value": "New",
"action": "CreateNewDoc"},{"value": "Open", "action":
"OpenDoc"},{"value": "Close", "action": "CloseDoc"}]}';
stringhtml = '<p>Hello World!</p>';
alert(isJson(stringjson));
alert(isJson(stringhtml));
bye
--
gianiaz.net - web solutions
via piedo, 58 - 23020 tresivio (so) - italy
+39 347 7196482