Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i have this string of values and don't understand how to get the object array name and values of object items in java.
{
"employees": [
{ "firstName":"Rajesh" , "lastName":"Putta" },
{ "firstName":"Rajesh" , "lastName":"P" },
{ "firstName":"first name" , "lastName":"last name" }
]
}
This is basically a json stirng. Check more about it here:
JSON (JavaScript Object Notation) is a lightweight data-interchange
format. It is easy for humans to read and write. It is easy for
machines to parse and generate. It is based on a subset of the
JavaScript Programming Language, Standard ECMA-262 3rd Edition -
December 1999. JSON is a text format that is completely language
independent but uses conventions that are familiar to programmers of
the C-family of languages, including C, C++, C#, Java, JavaScript,
Perl, Python, and many others. These properties make JSON an ideal
data-interchange language.
You can parse it using a json parser such as
simpleJson
Jackson
GSon
Try these parsers, if you get stuck with the code then share your code and the problem.
Related
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 1 year ago.
Improve this question
I want to use both python and java in the same program. Since the print() function of python is better, but java's int variable; is more efficient.
If I'm interpreting correctly, you want to use to use both interchangeably in the same file, so you'd end up with code like:
def main():
int x = 5;
print(x)
This is impossible, because there would be ambiguity when trying to interpret code if you allowed constructs from both languages. For example, "X" + 1 is allowed in java, and would give you the string "X1". In python, it would give you an error because you can't add an int to a string. This would mean that there would be no way to know what your code should do because it's runnable in both languages.
This is a problem that all of us face, where we like some parts of some languages and other parts of other languages. The solution is pretty much just to decide what's most important, choose one language based on that, and then put up with the parts you don't like.
You can use Jython, which is a Python implementation based on the JVM/JDK. This allows calling between Java and Python code in both directions.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I am looking to parse ADA code and construct its AST using Java. My belief was that there's a parser written in Java to parse almost every programming language, however after days of research I haven't found anything.
The only promising tool I've found is libadalang (https://github.com/AdaCore/libadalang) by Adacore. However, this only provides api for Ada and Python (although in the readme file Java is mentioned).
Do you have anything to suggest? If there's no direct way of parsing Ada using Java, is any of you familiar with any library that could work as an intermediate? For example, parse Ada using XXX tool and store the AST in a schema (e.g. XML) and then parse the XML using Java?
I'm one of the Libadalang developers, we have indeed planned adding Java bindings at some point, but this is not a high priority item for the moment.
Having a serializer for a common format is something that would be quite easy to add though, especially to the python API were you have full introspection on the tree.
Here is a JSON serializer for the python API of Libadalang:
import json
def node_to_data(self):
if isinstance(self, ASTList):
return [i.to_data() for i in self if i is not None]
else:
return {n: v.to_data()
for n, v in self.iter_fields(with_properties=False)
if v is not None}
def token_to_data(self):
return {"kind": "Token", "token_kind": self.kind, "text": self.text}
ASTNode.to_data = node_to_data
Token.to_data = token_to_data
ASTNode.to_json = lambda self: json.dumps(self.to_data())
I'll add this to the development version of Libadalang soon!
I think I've read that it is possible to call native C libraries from Java.
You could make a C binding to ASIS (Ada Semantic Interface Specification), and then call that from Java.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
In java I noticed there are methods associated with conversion of strings and those methods sometimes use the word "parse" in the name of the method. For example the static method,
static int parseInt(String str)
is used to convert a string into int. My question is this. Is "parse" short for another word? Is it just a random word or did it come from somewhere else in some other programming context in Java or anywhere else?
From wikipedia:
Parsing or syntactic analysis is the process of analysing a string of symbols, either in natural language or in computer languages, according to the rules of a formal grammar. The term parsing comes from Latin pars (ōrātiōnis), meaning part (of speech).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
here is the non-oop way of doing it:
When someone presses a day on a calendar, we need to find out the day, and path. Here is the non-oop way of storing that information:
A string was created with a "-" delimiter between each piece of info we need, like this:
12-c:\files\john_doe.png
Then it was stored in an array. However, to retrieve the data, we then use the "split" function like this.
for (int t = 0;t < day_and_path.length;t++)
{
String[] day_from_db = day_and_path[t].split("-");
String day_db = day_from_db[0];
String path_db = day_from_db[1];
However the OOP way is, make a class with properties: day, path. Then store them into an array of objects.
Which way is better and why?
If you use String#split, you'll be dealing with an array of strings. If all you do is assign the strings to local variables, then there is no point in making a class for that.
If you want to hold on to the string parts and pass them around to other methods, then it begins to make sense to have an object which will conveniently encapsulate those strings.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string that looks like this
[
{"last_name":"Aiken","first_name":"George","state":"VT","party":"R"},
{"last_name":"Allott","first_name":"Gordon","state":"CO","party":"R"},
{"last_name":"Anderson","first_name":"Clinton","state":"NM","party":"L"},
{"last_name":"Bartlett","first_name":"Edward","state":"AK","party":"D"}
]
That is stored in a variable.
How would I add this string to an array so that I can then access the data (no punctuation)
is needed.
The string you have mentioned is a JSON string.
JSON (JavaScript Object Notation) is a lightweight data-interchange
format. It is easy for humans to read and write. It is easy for
machines to parse and generate. It is based on a subset of the
JavaScript Programming Language, Standard ECMA-262 3rd Edition -
December 1999. JSON is a text format that is completely language
independent but uses conventions that are familiar to programmers of
the C-family of languages, including C, C++, C#, Java, JavaScript,
Perl, Python, and many others. These properties make JSON an ideal
data-interchange language.
You should use a parser to parse the JSON string and fetch its elements. There are multiple JSON parser available on internet such as:
Jackson
JSON Simple
GSON
JSON is built on two structures:
A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed
list, or associative array.
An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
---> source & more info: http://www.json.org/
You just need to parse json object and iterate through json array to store the values in array.
These links may be helpful to you:
Link 1 to parse json
Link 2 to parse json
Link 3 to parse json