Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate JsonStringer for this Json Data Format?

Tags:

json

android

hello i have a JSON data format can anyone please help me to make dynamic JSONStringer object for this String

    {"Text":"Hello Simple Text",
"Files":[{"ContentType":"image/png",
"Content":"iVBORw0KGgoAAAANSUhEUgAAAR8AAACMCAIAAADKsDpDAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAB3RJTUUH2wYWDzIB3zSYdQAAAAd0RVh0QXV0aG9yAKmuzEgAAAAMdEVYdERlc2NyaXB0aW9uABMJISMAAAAKdEVYdENvcHlyaWdodACsD8w6AAAADnRFWHRDcmVhdGlvbiB0aW1lADX3DwkAAAAJdEVYdFNvZnR3YXJlAF1w/zoAAAALdEVYdERpc2NsYWltZXIAt8C0jwAAAAh0RVh0V2FybmluZwDAG+aHAAAAB3RFWHRTb3VyY2UA9f+D6wAAAAh0RVh0Q29tbWVudAD2zJa/AAAABnRFWHRUaXRsZQCo7tInAAABAElEQVR4nO2de1zUVf7/3+dzmwsMoCgDXgARBO/"}],
"AuthToken":"XkWQRd65+H+iPtlOoAEYAR0jrzB1o3UV"}

i have used

jsonstr = new JSONStringer().object().key("Text")
                            .value(msg).key("Files").array().object().key(
                                    "ContentType").value("image/png").key(
                                    "Content").value(enimg)
                            .endObject().endArray().key("AuthToken").value(token)
                            .endObject();

but the server is giving me fault message in return, not accepting the data.

like image 814
MKJParekh Avatar asked Sep 30 '11 07:09

MKJParekh


People also ask

How do I format a JSON file?

Formatting# You can format your JSON document using Ctrl+Shift+I or Format Document from the context menu.

How do I create a JSONArray?

Create a JSON array by instantiating the JSONArray class and add, elements to the created array using the add() method of the JSONArray class.

How do you pass a JSON object into a map?

The first way to convert JSON to Map in Java is by using Jackson. In Jackson, there is a method available with the name readValue(json, Map. class) and we can call this method by using the ObjectMapper object. This method takes JSON as input.

How do you create a JSON object?

To create an object we need to use opening and closing curly braces {} and then inside of that we'll put all of the key value pairs that make up our object. Every single property inside the JSON is a key value pair. The key must be surrounded by double "" quotes followed by a colon : and then the value for that key.


1 Answers

actually i was doing the right thing..everything was OK.. the problem was with org.json package it was not accurate with Base64 string

i switched to another library and all worked..

https://stackoverflow.com/questions/338586/a-better-java-json-library

see the above question for another json libraries

that was problem with org.json

i switched to another..and all it works

nesting too deep in JSON... should I switch to XML?

like image 187
MKJParekh Avatar answered Sep 26 '22 03:09

MKJParekh