I have a js file which is in json format and i want to convert this file to a human readable format.Is there any external software which does that or i have to code it??Am new to this stuff.
Json is a format which looks like plain text. I guess you know what you are asking. If you need to convert a file containing Json text to a readable format, you need to convert that to an Object and implement toString() method(assuming converting to Java object) to print or write to another file in a much readabe format. You can use any Json API for this, for example Jackson JSON API.
ObjectMapper obj = new ObjectMapper();
T t=obj.readValue(File src, Class<T> valueType)
t.toString(); //this must have been implemented
Related
I trying to convert some HTML string to JSON string and then to objects, to store any images data on some page to TXT file.
I used Curl to download the page data (and can use nlohmann/json to convert JSON strings to object)
Now I need some way to convert HTML String to JSON Objects or find a way to convert the relevant for me data (like and tags)
Thanks for help
I was expecting a JSON string while testing an API using Postman, but instead got this:
{city=Shanghai, work=112-454-7895, fax=788-899-7899}
Obviously I cannot put that into Google and ask what format is it, hence I am asking it here. Postman also says it is a 'bad string'.
I have never seen the above data serialization format. If someone can point the format out to me I would be able to find and use a converter. Additional suggestion with converting it to POJO or JSON are welcome as well.
I figured out that the above format is a stringified version of a HashMap<String, String>, and that there is no direct way to convert it into JSON/POJO. Converting it into json string requires additional work but is fairly straightforward.
What will be the preferred way of converting JSON to XML file? Is it better to use web-service or any Java component? I tried using web-service and still wanted to cross-check if there is any other option to do this.
Convert JSON text contained in string json into an XML node
XmlDocument Xmldoc = JsonConvert.DeserializeXmlNode(json);
Here is the documentation:
Json to xml
I've been trying for a while to get a byte[] from my database blob and then parse it to json and send it to my clients. I first get the blob from the database and then I get the byte array by doing:
MyObject temp = new MyObject()
Blob icon = dbResult.getBlob(1);
temp.setIcon(icon.getBytes(1, (int)icon.length()));
Later on I parse MyObject to a json string which I send back to clients. But it seems that the json string becomes pretty much corrupted when parsing the byte[].
An example of how it might look:
[{"icon":"/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAFQAPwDASIAAhEBAxEB/8QAHAAAAQUBAQEAAAAAAAAAAAAAAgEDBAUGAAcI
I parsed this to json in my webservice which is a jersery webservice. When i try to parse it from json into a class object at client side, it throws IllegalStateException(Gson).
Anyone knows what this is about and what i'm doing wrong?
If you try to transfer binary data using json, you better explicitly encode it with base64 and then decode it on receiver's side. JSON isn't designed to wrap binaries, so the problems when trying to make this were expectable.
In AS3, I want lo load a file text with URLLoader. In the file text I have the following string:
{a:1,b:"string",c:["one","two"]}
Is it possible (once loaded) to convert it to an Object?
There is no intrinsic deserializer built into the language, no. But if your text file sticks to the JSON standard, then you could use a JSON parser to do the conversion for you: http://code.google.com/p/as3corelib/source/browse/#svn%2Ftrunk%2Fsrc%2Fcom%2Fadobe%2Fserialization%2Fjson
Or, if you cannot adhere to JSON, you could always write your own deserializer.
What you need is to eval the string to create the object.
This is done natively in javascript and AS2. AS3 however does not support this function.
But all is not lost. The people at Hurlant have created a library that does this "almost" as good as native JavaScript.
Here is a good example.
And another library example using d.eval
I would like to point out though that if you have accept to the source of the object string that you create a JSON object out of it. The JSON libraries are usually much easier and more reliable to use then the libraries that do Eval.
Your string is a sting with JSON format. Use JSONDecoder to decode it to an Object, like this:
var dc:JSONDecoder = new JSONDecoder("{a:1,b:'string',c:['one','two']}");
var ob:Object = dc.getValue();