Jquery function to convert java data to json [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there a jquery function that will convert a java data object to a json?
I am using the HTTPResponse object to serve up my object to my ajax, which returns a String object.
note:
JSON.parse wont work
I cant use any json parsing libraries

Try using $.getJSON
var onSuccess = function(data) {
//data is now a javascript object
};
$.getJSON("your-url").done(onSuccess);

Related

How to convert two dates in json string to array in json? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
i have following issue .
I send JSON like this to backend :
{"n":"dsad","t":"asda","term":"2021-06-26, 2021-06-30"}
I need to send this "term" not like this just like array ->
"term": [
"2021-07-08",
"2021-07-06"
]
How can i do it?
I have angular in frontend and Java as backend.
Thanks for help.
To acheave this you can use the split function in Jacascript and split on the , . This will give an array you can use to replace the term object.
object.term = object.term.replace(" ","").split(",")
Create an interface so you are forced to build the object in the way needed.
export interface InterfaceName {
n: string;
t: string;
term: Date[];
}

How to get only the "make" and "model" data from this json output in either java or jquery. Java isp preferred [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How to extract make and model from this json output.
[
"{\"_id\":{\"$oid\":\"5a81d2136da3cd4c41b21509\"},\"make\":\"maruti\",\"model\":\"astar\",\"year\":1998}"
]
Use JSON.parse to convert string to the JS object and then access the properties using dot notation.
You don't even need jQuery for this. Following is an example:
let data = [
"{\"_id\":{\"$oid\":\"5a81d2136da3cd4c41b21509\"},\"make\":\"maruti\",\"model\":\"astar\",\"year\":1998}"
];
data[0] = JSON.parse(data[0]);
console.log(data[0].make, data[0].model);
To extract JSON data in jQuery you can do following.
var d = $.parseJSON(data);
var make = data.make;
var model = data.model;
in make and model you will get your desired output.
Hope it helps.

Masking some value inside Json string in Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Suppose i have below Json String:
{
"name":"noor",
"pass":"12345"
}
I want to mask pass value using Regex, like below
{
"name":"noor",
"pass":"*****"
}
How i can do it, using Java regex?
Try this:
"pass":"(.*?)"
As seen on: https://regex101.com/r/cK4bD0/1
try this
String jsonString = "{ \"name\":\"noor\", \"pass\":\"12345\" }";
String result = jsonString.replaceAll("(?<=pass\":\")(.*?)(?=\")", "*****");
System.out.println(result);
{[^}]*"pass"\s*:\s*"(.*?)"[^}]*}
Here is the DEMO: https://regex101.com/r/nL3tP2/2

How to convert String to an Array In Java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a String and I want convert it to a String array without using a JsonObject.
I searched many topics, but I can't solve my problem.
My String is like:
String str="[{"India":{"State":"Gujarat","City":"Rajkot","Pin":360330,"Place":"AT Rajkot"}}]";
And I want output As Array like:
India
Gujarat
Rajkot
360330
AT Rajkot
How can I get an array like that output, without using jsonObject?
You are asking how to parse JSON. You need to use a JsonObject or another JSON library. If you want to learn how to do this, read the several thousand lines of source code in JsonObject and learn how to write a JSON parser. Then, write a JSON parser, which will do what you want.
In other words, what you are asking is not technically incorrect, but ridiculous.

(GSON) Collection to Json String [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have the following row in my function:
Collection<Song> songs = a.getListOfSongs();
There are all required annotations in the Song class.
Need to return JSON String using GSON lib.
Thank you!
Use new Gson().toJson(songs). Although when you try to make Song bean from this json, you might have to face some casting issues like, int value would have converted to double, char to string...as GSON uses its intelligence to resolve such types
Gson gson = new Gson();
String json = gson.toJson(songs);

Categories

Resources