I have established a connection but unable to access data.Help needed
JSON data
[
{
"name": "Margherita",
"price": 170
},
{
"name": "Corn MAnia",
"price": 170
},
{
"name": "Triple Tango",
"price": 210
}
]
In MarkLogic Server, you can use the XPath language to traverse JSON and retrieve data. Code can be written in the Xquery language or Server Side JavaScript:
xquery version "1.0-ml";
let $doc:= xdmp:unquote('{"root":[{"name": "Margherita","price": 170}, {"name": "Corn MAnia","price": 170}, {"name": "Triple Tango","price": 210}]}')
return xdmp:document-insert('/doc/names.json', $doc)
To get data, use:
doc('/doc/names.json')/root[1]/name
or
doc('/doc/names.json')/root[2]/price/data()
Related
I want to make a categories screen, the backend returns a nested json with 4 trees in total if I'm not mistaken,
example:
when I press the most general tree of the categories, I would like it to be displayed as a dropdown and there, put the children of this category, the ones that come in the json clearly, hope to explain myself well.
I have to fill these widgets, their text or titles with the text that comes clearly in the json, but I'm not going to be calling the endpoint every time I want to paint the titles, i have to save what comes in the json in the sqlite, and then extract from there the texts to put on categories screen ... how can I do this? I'm new, never build a structure like that, I have to do it with sqlite, but I wouldn't know how to start or how to build the tables, if I make a table, only the first tree of the categories will go, and the rest? the children of the nested json? Could someone guide me?
I leave you a piece of the json (for other reasons I can not put it complete) to put them a little more in context
{
"res": 0,
"categorias": [
{
"id": 1,
"name": "Bolsas",
"img": "hogar.png",
"titulo": 0,
"children": [
{
"id": 11,
"name": "Para llevar",
"img": "llevar.png",
"titulo": 0
},
{
"id": 12,
"name": "Para Conservar",
"img": "consrvar.png",
"titulo": 0
},
{
"id": 13,
"name": "Para Organizar",
"img": "organizar.png",
"titulo": 0
},
{
"id": 14,
"name": "Multipack",
"img": "multipack.png",
"titulo": 0
}
]
},
{
"id": 2,
"name": "Cuidado del aire",
"img": "aire.png",
"titulo": 0,
"children": [
{
"id": 21,
"name": "Instantaneo",
"img": "instantaneo.png",
"titulo": 0,
"children": [
{
"id": 211,
"name": "Aerosol",
"img": "llevar.png",
"titulo": 0
},
{
"id": 212,
"name": "Toque",
"img": "consrvar.png",
"titulo": 0
}
]
},
You have several option to work with json and sqlite:
Just put your json as string in row on table and then select as string and convert to json.
You can use similar approach from paragraph 1 bud with using sqlite's json extension. It adds possibility to select of update parts of json by special query syntax. To use sqlite with this extension u will need custom build of sqlite like sqlite-android (with have many other benefits).
You can crate separate sqlite table from each level fo json nesting (depends on your need of granularity). For example you can create table categorias with columsn(categorias_id, categorias_name, categorias_img, categorias_titulo), table categorias_childrens with columns(categorias_id, id, name, img, titulo, categorias_childrens_id).
In this case all rows of categorias_childrens table related with categorias.categorias_id contains categorias.categorias_id in categorias_childrens.categorias_id column. And all rows related with some of categorias_childrens row contains categorias_childrens.categorias_id in categorias_childrens.categorias_childrens_id column (situation when children.id.21 has childrens ).
Or u can combine approaches fro example: create table categorias with columsn(categorias_id, categorias_name, categorias_img, categorias_titulo, children) where column children will be contains string json value.
I am trying to consume below record using JSON with Volley, but it is not a JSONArray, How can I change it to use it in :
JsonArrayRequest movieReq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
Mean while, The URL in the record seems not correct. How to remove extar forward slashes from url or I can use it to fetch the JPG image?
{
"ID": "131",
"Lead": "",
"Title": "\u06f2\u06f0 \u06af\u0644 \u0641\u0648\u0642 \u0627\u0644\u0639\u0627\u062f\u0647 \u0631\u0648\u0646\u0627\u0644\u062f\u0648 \u062f\u0631 \u0644\u06cc\u06af \u0642\u0647\u0631\u0645\u0627\u0646\u0627\u0646",
"ContentTime": "09:56",
"TypeContent": "public",
"PTime": "1395\/05\/09 - 11:47",
"Content": " <\/div>",
"Tags": "\u0641\u0648\u062a\u0628\u0627\u0644#\u0631\u0648\u0646\u0627\u0644\u062f\u0648#\u0648\u0631\u0632\u0634\u06cc#######",
"Price": "0",
"GID": "106",
"GTitle": "\u0648\u0631\u0632\u0634\u06cc",
"PicURL": "http:\/\/video.dmedia.ir\/images\/news\/131\/thumb_131.jpg",
"comment_count": "0",
"view_count": "0",
"Media": [{
"GID": "359",
"GType": "mp4",
"Title": "",
"URL": "http:\/\/video.dmedia.ir\/images\/news\/131\/media\/359.mp4",
"ADV": 0
}],
"smscontent": null,
"Rels": [{
"RelID": "130",
"RelTitle": " \u0645\u0647\u062f\u0648\u06cc: \u062f\u0648\u0633\u062a \u062f\u0627\u0631\u0645 \u0648\u0627\u0644\u06cc\u0628\u0627\u0644\u0645 \u0628\u0627 \u06cc\u06a9 \u062e\u0627\u0637\u0631\u0647 \u062e\u0648\u0628 \u062a\u0645\u0648\u0645 \u0634\u0648\u062f"
}],
"Comments": []
}
Solution:
We can make JSON object request and JSON array request:
I found this helpful.
http://www.androidhive.info/2014/09/android-json-parsing-using-volley/
hi there is one plugin Gson for android studio.You need to install.Then go to CTRL + insert.
You can create gson file.
Enter some name for java file.
Click that file then Paste you json data. Click ok.
You can see your created json to gson format.
thanks hope this will help you.
create model class for this data then use follwing code
ModelClass class=new GSON.fromJSON("your Data ", ModelClass.class )
Hi I am new to Android and i am developing one app in which i will send request to server and get json data.The problem is that when receive response fron server and when i trying to get that i get one exception
java.lang.String cannot converted to JSONobject
Your server returned incorrect json-data. There are extra " that should be removed.
It should look similar to
[{
"image": "http://eprintpost.com/images/savepreflab/uploadSave/69120e7d-31e0-46ac-bf07-e86778bc2866.jpg",
"productid": "255",
"oldprice": "250",
"city": "Pune",
"price": "200",
"labname": "Emotions",
"productname": "Sublimation Bag (6058)"
}, {
"image": "http://eprintpost.com/images/savepreflab/uploadSave/48e9420c-3bd2-4c89-91a3-0de3346c072f.jpg",
"productid": "481",
"oldprice": "1000",
"city": "Coimbatore",
"price": "500",
"labname": "savithri photo house",
"productname": "camera toploader 450AW Black"
}, {
"image": "http://eprintpost.com/images/savepreflab/uploadSave/741e6549-94be-439d-b823-0bd8b26bb0ce.jpg",
"productid": "556",
"oldprice": "1000",
"city": "Dharwad",
"price": "400",
"labname": "Foto Magic Studio And Lab",
"productname": "07.jpg"
}]
Could you put all your error log cat ? Where is exactly throw this error
type java.lang.String cannot be converted to JSONObject
Your error is parsing from String to JSONObject so let focus on which lines make a parsing to JSONObject
friends:
I get a response from remote server as follows on Android:
{
"items": {
"persons": [
{
"id": "200120",
"name": "Bill"
},
{
"id": "200121",
"name": "Jim"
}
],
"tasks": [
{
"id": "001",
"name": "Fetch ten books",
"deadline": "5:30 p.m.",
"scores": "10"
},
{
"id": "002",
"name": "Fetch thirty books",
"deadline": "5:30 p.m.",
"scores": "30"
}
],
"intro": "This is a funny game."
},
"otherObj": []
}
And I want to save it to phones. I do not think it a good choice to save it into databases. However it read not fast if put the response to SharedPreferences file. Is there any other way?
No need to save this data into database as these value are dynamic and will change time to time.
In your Activity, call the API and get JSON as response and then parse this JSON and show it on device.
To store it on device u can use Singleton class also.
For JSON parser refer to http://www.tutorialspoint.com/android/android_json_parser.htm
You can first save your data into objects and at last into Object Array and then Save to database.(If your data is dynamic it is better you only deal with Object not database)
For saving to database you can use
db.beginTransaction();
for(object : ObjectArray){
db.dboperation();
}
db.setTransactionSuccessful();
db.endTransaction();
I successfully got my Android app to sync with my iriscouch database. In this database I have about 100 documents, each representing one line of public transport with its corresponding stations, like:
{
"_id": "1",
"_rev": "1-9658663cc48789829fb505ce2e0fd4ce",
"name": "1",
"stations": [
{
"_id": "Stefan-Fadinger-Platz",
"name": "Stefan-Fadinger-Platz",
"long": "16.35464100",
"lat": "48.16771000"
},
{
"_id": "Julius-Raab-Platz",
"name": "Julius-Raab-Platz",
"long": "16.38323500",
"lat": "48.21135300"
},
{
"_id": "Schwedenplatz U",
"name": "Schwedenplatz U",
"long": "16.37765200",
"lat": "48.21178500"
},
....
}
How can I access this data from Android based on user selection, for example getting all stations for line 1?
As far as I've read, I need to create a view for each query, but I don't think manually creating 100 views is performant. Is there a dynamic way?
You can create views locally in TouchDB.
http://wiki.apache.org/couchdb/HTTP_view_API
They work the same as regular CouchDB views. You can provide parameters to the views that help you filter based on a user selection.