I have a grails controller whose last line is
render results as JSON
It is being rendered to an iframe. When firefox processes this, it tries to download the json file. Is this normal? The only way I've been able to get around this is to convert it to a string and then handle it on the javascript side.
I have a grails controller in which I wrote something like this and I've got String message. Try this example.
String msg = g.message(code: "default.errors.login.fail")
render([error: msg] as JSON)
Related
I'm using latest JMeter 3.3 testing server APIs,
I'm getting a valid JSON response from server in Text view which looks OK
{"code":"1","message":"Template Name not found"}
But when changing to JSON format is shows extra : characters
{
: "code":"1",
: "message":"Template Name not found"
}
In View Results Tree it supposes to show in tree style:
JSON The JSON view will show the response in tree style (also handles JSON embedded in JavaScript).
I don't understand why we need such parser and it seems that it's unnecessary for JSON responses, or maybe it seems just a bug in the JMeter UI parser?
It was a bug in JMeter render that was fix and will be available in next version
change it to a simple four space "tab"
I'm new to the World of triplets :-) I'm trying to use DotNetRDF to load the SOLR searchresult into a Graph using DotNetRDF.
The URL I'm getting data from is:
https://nvv.entryscape.net/store/search?type=solr&query=rdfType:https%5C%3A%2F%2Fnvv.entryscape.net%2Fns%2FDocument+AND+context:https%5C%3A%2F%2Fnvv.entryscape.net%2Fstore%2F1
The format is supposed to be "RDF/JSON". No matter what parser or what I try - I only get "invalid URI". Have tried to load from the URL and also tried downloadning the result to a file and load from file, same error.
I'm using VS2017 and have "nugetted" the latest version of DotNetRdf.
Please help me, what am I missing?
Regards,
Lars Siden
It looks like the JSON being returned by that endpoint is not valid RDF/JSON. It does appear to contain some RDF/JSON fragments but they are wrapped up inside another JSON structure. The RDFJSONParser in dotNetRDF requires that your entire JSON document be a single, valid chunk of RDF/JSON.
The value at resource.children[*].metadata is an RDF/JSON object. So is the value at resource.children[*].info. The rest is wrapper using property names that are not valid IRIs (hence the parser error message).
Unfortunately there is no easy way to skip over the rest of the JSON document and only parse the valid bits. To do that you will need to load the JSON document using Newtonsoft.JSON and then serialize each valid RDF/JSON object you are interested in as a string and load that using the RDFJSONParser's Load(IGraph, TextReader) or Parse(IRdfHandler, TextReader) method.
i'm developping a program in java ee.
i know how to display a view from a servlet with a code like this
this.getServletContext().getRequestDispatcher( VUE).forward( request, response );
where my view (VUE) is in a jsp page.
i know also how to return a json object with something like that
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(jsonErreurEtRole);
I'm using google Gson to convert java objects.
Now i want to return a json object that contain a view in one field and some others messages in others field.
But i can't find how to do it.
Is there a way for that ?
EDIT
I will try to be more clear,
My problem is that : users ara requesting content by calling a servlet (a controller), i check their right on that content. And if they don't have right i send a message like "you don't have right ..."
that message should not replace any content in the html page but just appear as a notification.
So i wanted to return a json object like [message, content]
by the way i solved my problem by sending only message in a json object if user don't have right and html content if he has. And in je jquery code i'm testing the return type of the response.
I used this post :
jQuery ajax returned data: json and html mix?
I'm horribly sorry if there is a post for this, I tried to search but didn't find a answer.
Problem:
I'm calling a web service and receiving not so well formed JSON data from a Dynamics Nav service:
JSON:
"[{\"type\":\"2\",\"number\":\"VHT3866\",\"location\":\"Delta\",\"destinationNo\":\"\",\"contactName\":\"Jesus\",\"shipToName\":\"Lord jesus\",\"highPriority\":\"false\",\"hasComment\":\"true\",\"assignedTo\":\"\",\"source\":\"\"},{\"type\":\"2\",\"number\":\"VHT3866\",\"location\":\"Delta\",\"destinationNo\":\"\",\"contactName\":\"Jesus\",\"shipToName\":\"Lord jesus\",\"highPriority\":\"false\",\"hasComment\":\"true\",\"assignedTo\":\"\",\"source\":\"\"}]"
I then take this JSON and use angular.fromJson(json) to get it properly.
It doesn't seem to change into an array of javascript objects, but just plain text.
However if I take the same JSON and just put it manually in like this:
var json = angular.fromJson(stringfromserver);
It turns into a proper javascript object and ng-repeat throws no error.
I found an answer on Quora:
--- Le Batoure,
Angular from json is now strict so assuming that this string is from a trusted source you would have to use "eval()" plus surround the call in parenthesis for it to work
var hatsData = angular.fromJson(eval("(" + hats + ")"))
If you bring your JSON from http request for example you don't need to use the fromJson method.
The JSON is automatically parsed by Angular and you can use it directly.
I want to parse the response coming from the server in JSON format. I have done some googling but i can't find any library or jar kind of thing.
Everywhere there is provided open source code as zip file.
How can i achieve this? if there is no jar available for blackberry then how to use that open source code in my application??
There is an open source JSON for J2ME API on Mobile and Embedded Application Developers Project
Also you can download JSON ME (Zip file) at JSON.org not supported anymore. But you can get it from here.
I believe you can simply copy content of json project src folder to your Blackberry project src folder, refresh it in eclipse package explorer and build it.
See for details: Using JavaScript Object Notation (JSON) in Java ME for Data Interchange
I am developing a Blackberry client application and I confronted the same problem. I was searching for JSON way of parsing the response which I get from the server. I am using Eclipse plug-in for BB as IDE and it comes with BB SDK including the ones for JSON.
The easiest answer to this question is that:
Initially do not forget to use this import statement:
import org.json.me.JSONObject;
Then assign your JSON formatted response from the server to a String variable:
String jsonStr = "{\"team\":\"Bursaspor\",\"manager\":\"Ertuğrul Sağlam\",\"year\":\"2010\"}";
Create a JSONObject:
JSONObject obj = new JSONObject(jsonStr);
i.e. if you want to use the value of the "team" field which is "Bursaspor" then you should use your JSONObject like this:
obj.getString("team")
This call will return the string value which is "Bursaspor".
P.S: I inspired this solution from this site which simply explains the solution of the same problem for Android development.
http://trandroid.com/2010/05/17/android-ile-json-parse-etme-ornegi-1/
When you got response string then use this code
try {
JSONObject jsonres = new JSONObject(jsons);
System.out.println("Preview icon from jsonresp:"+jsonres.getString("mydata"));
} catch (JSONException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
one thing jsons is your response string which is in json format & mydata your key of data so you can get your data from JSONObject. Thnks
chek this post to find out how to get JSONME source from SVN:
http://www.java-n-me.com/2010/11/how-to-import-source-code-from-svn-to.html
Hope it helps someone.
You can also try :
http://pensivemode.fileave.com/verified_json.jar
I was also looking for a jar version of json (to link along my lib) :
https://radheshg.wordpress.com/tag/json/
but it seems not portable :
Building example
C:\Program Files (x86)\Research In Motion\BlackBerry JDE 4.5.0\bin\rapc.exe -quiet import="C:\Program Files (x86)\Research In Motion\BlackBerry JDE 4.5.0\lib\net_rim_api.jar";lib\${PROJECT}.jar;lib\json.jar codename=example\example example\example.rapc warnkey=0x52424200;0x52525400;0x52435200 Y:\src\${PROJECT}-java.git\example\src\mypackage\MyApp.java Y:\src\${PROJECT}-java.git\example\src\mypackage\MyScreen.java
tmp3139/org/json/me/JSONArray.class: Error!: Invalid class file: Incorrect classfile version
Error while building project
http://supportforums.blackberry.com/t5/Java-Development/JSON-library/m-p/573687#M117982
So far JSON.simple is looking like a great viable option.
JSONParser parser=new JSONParser();
System.out.println("=======decode=======");
String s="[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
Object obj=parser.parse(s);
JSONArray array=(JSONArray)obj;
System.out.println("======the 2nd element of array======");
System.out.println(array.get(1));
System.out.println();