I create a wallpaper apps and I found this error
org.json.JSONException: No value for index
and the apps can't start
Here's my json
]
{
"wallpaper_index": "1",
"wallpaper_name": "Wallpaper1",
"wallpaper_site_name": "Wallpaper",
"wallpaper_site_url": "http://google.com",
"wallpaper_url": "https://i.imgur.com/Z0UGroX.jpg"
},
{
"wallpaper_index": "2",
"wallpaper_name": "Wallpaper2",
"wallpaper_site_name": "Wallpaper",
"wallpaper_site_url": "http://google.com",
"wallpaper_url": "https://i.imgur.com/nSx1uN8.jpg"
},
{
"wallpaper_index": "3",
"wallpaper_name": "Wallpaper2",
"wallpaper_site_name": "Wallpaper",
"wallpaper_site_url": "http://google.com",
"wallpaper_url": "https://i.imgur.com/ezhbnQR.jpg"
},
]
How to fix it ?
Thanks in advance
NOTE: Your json is not valid. It should start with the "[" symbol ( and not with "]" one ) and you should remove the comma on
second-last row. Here is the correct json after the revision:
[
{
"wallpaper_index":"1",
"wallpaper_name":"Wallpaper1",
"wallpaper_site_name":"Wallpaper",
"wallpaper_site_url":"http://google.com",
"wallpaper_url":"https://i.imgur.com/Z0UGroX.jpg"
},
{
"wallpaper_index":"2",
"wallpaper_name":"Wallpaper2",
"wallpaper_site_name":"Wallpaper",
"wallpaper_site_url":"http://google.com",
"wallpaper_url":"https://i.imgur.com/nSx1uN8.jpg"
},
{
"wallpaper_index":"3",
"wallpaper_name":"Wallpaper2",
"wallpaper_site_name":"Wallpaper",
"wallpaper_site_url":"http://google.com",
"wallpaper_url":"https://i.imgur.com/ezhbnQR.jpg"
}
]
By the way, assuming you just wrote the json wrong doing the question, the issue is that you are trying to get value for a not existing entry ( "index" ) on your json array elements.
According to your json, if you change for example the requested element to "wallpaper_index" it will work.
Related
Answers to a questionnaire are stored in json in a column in this table. I need to pull out the answer to a specific question stored within this column, but am struggling to do so.
I want to get the postValue '123456789' as 'Incorporation Number'
I am not sure how to get the specific child element value - any help much appreciated.
select json_extract(table.json_column, '$.user_data.element.postValue') as 'json'
from table
where table.id = 123
the json looks something like the below:
{
"risk_data":[
],
"user_data":[
"elements":[
{
"postName":"postNameInput",
"postValue":"TEST COMPANY"
}
],
"language":"english",
"elementId":"100",
"sectionId":"9",
"weightage":null,
"isHyperLink":0,
"elementIndex":0,
"elementTitle":{
"english":"Company's Full Legal Name"
},
"hyperLinkUrl":null,
"isWorkFlowNa":0,
"sectionIndex":0,
"sectionTitle":{
"english":"Basic Company Information"
},
"hyperLinkText":null,
"isMultiSelect":0,
"selectedChart":null,
"dataAttributes":null,
"elementTitleAbb":{
"english":"Company's Full Legal Name"
},
"isHiddenElement":0,
"isHiddenSection":0,
"elementInputType":"input",
"elementFooterText":null,
"elementHeaderText":null,
"elementDescription":null,
"hyperLinkTextAfter":null,
"question_abb_table":null,
"hyperLinkTextBefore":null,
"enableSelfReportingForManageThirdParty":0,
"enableSelfReportingForThirdPartyProfile":0
}, {
"elements":[
{
"postName":"postNameInput",
"postValue":"123456789"
}
],
"language":"english",
"elementId":"101",
"sectionId":"10",
"weightage":null,
"isHyperLink":0,
"elementIndex":4,
"elementTitle":{
"english":"Incorporation Number"
},
"hyperLinkUrl":null,
"isWorkFlowNa":0,
"sectionIndex":3,
"sectionTitle":{
"english":"Organisational Structure"
},
"hyperLinkText":null,
"isMultiSelect":0,
"selectedChart":null,
"dataAttributes":null,
"elementTitleAbb":{
"english":"Incorporation Number"
},
"isHiddenElement":0,
"isHiddenSection":0,
"elementInputType":"input",
"elementFooterText":null,
"elementHeaderText":null,
"elementDescription":null,
"hyperLinkTextAfter":null,
"question_abb_table":null,
"hyperLinkTextBefore":null,
"enableSelfReportingForManageThirdParty":0,
"enableSelfReportingForThirdPartyProfile":0
},
I have this JSON part:
{
"destination_addresses":[
"8000 AA Zwolle, Nederland"
],
"origin_addresses":[
"8100 AA Heino, Nederland"
],
"rows":[
{
"elements":[
{
"distance":{
"text":"14,6 km",
"value":14555
},
"duration":{
"text":"17 min.",
"value":1022
},
"status":"OK"
}
]
}
],
"status":"OK"
}
I want the regex to find the value 14555 and the value 1022 but not by searching for this numbers (because the numbers always change) but by searching by the node (value in distance and value in duration)
Any ideas?
"distance" : {.*"value" : ([0-9]+) (,.*)*}
Do you mean something like this? If you really need a RegExp to do this.
I don't know the language you use. But in most languages, you can just parse the JSON to an object. Then you can get that easily.
For example, in JavaScript, var obj = JSON.parse(str); may fit your demand.
I am a newbie to MongoDB. I am experimenting the various ways of extracting fields from a document inside collection.
Here in the below JSON document, I am finding it difficult to get extract it according to my need
{
"_id":1,
"dependencies":{
"a":[
"hello",
"hi"
],
"b":[
"Hmmm"
],
"c":[
"Vanilla",
"Strawberry",
"Pista"
],
"d":[
"Carrot",
"Cauliflower",
"Potato",
"Cabbage"
]
},
"productid":"25",
"date":"Thu Jul 30 11:36:49 PDT 2015"
}
I need to display the following output:
c:[
"Vanilla",
"Strawberry",
"Pista"
]
Can anyone please help me in solving it?
MongoDB Aggregation comes into rescue to get the result you are looking for :
$Project--> Passes along the documents with only the specified fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields.
db.collection.aggregate( [
{ $project :
{ c: "$dependencies.c", _id : 0 }
}
]).pretty();
As per the output you required, we just need to project ( display) the field "dependencies.c" , so we are creating a new field "c" and assigining the value of the "dependencies.c" into it.
Also by defalut "_id" field will be display along with the result, since you dont need it, so we are suppressing of the _id field by assigining "_id" : <0 or false>, so that it will not display the _id field in the output.
The above query will fetch you the result as below :
"c" : [
"Vanilla",
"Strawberry",
"Pista"
]
This is a single collection which has 2 json files. I am searching for a particular field: value in an object and the entire sub document must be returned in case of a match ( That particular sub document from the collection must be returned out of the 2 sub documents in the following collection). Thanks in advance.
{
"clinical_study": {
"#rank": "379",
"#comment": [],
"required_header": {
"download_date": "ClinicalTrials.gov processed this data on March 18, 2015",
"link_text": "Link to the current ClinicalTrials.gov record.",
"url": "http://clinicaltrials.gov/show/NCT00000738"
},
"id_info": {
"org_study_id": "ACTG 162",
"secondary_id": "11137",
"nct_id": "NCT00000738"
},
"brief_title": "Randomized, Double-Blind, Placebo-Controlled Trial of Nimodipine for the Neurological Manifestations of HIV-1",
"official_title": "Randomized, Double-Blind, Placebo-Controlled Trial of Nimodipine for the Neurological Manifestations of HIV-1",
}
{
"clinical_study": {
"#rank": "381",
"#comment": [],
"required_header": {
"download_date": "ClinicalTrials.gov processed this data on March 18, 2015",
"link_text": "Link to the current ClinicalTrials.gov record.",
"url": "http://clinicaltrials.gov/show/NCT00001292"
},
"id_info": {
"org_study_id": "920106",
"secondary_id": "92-C-0106",
"nct_id": "NCT00001292"
},
"brief_title": "Study of Scaling Disorders and Other Inherited Skin Diseases",
"official_title": "Clinical and Genetic Studies of the Scaling Disorders and Other Selected Genodermatoses",
}
Your example documents are malformed - right now both clinical_study keys are part of the same object, and that object is missing a closing }. I assume you want them to be two separate documents, although you call them subdocuments. It doesn't make sense to have them be subdocuments of a document if they are both named under the same key. You cannot save the document that way, and in the mongo shell it will silently replace the first instance of the key with the second:
> var x = { "a" : 1, "a" : 2 }
> x
{ "a" : 2 }
If you just want to return the clinical_study part of the document when you match on clinical_study.#rank, use projection:
db.test.find({ "clinical_study.#rank" : "379" }, { "clinical_study" : 1, "_id" : 0 })
If instead you meant for the clinical_study documents to be elements of an array inside a larger document, then use $. Here, clinical_study is now the name of an array field which has as its elements the two values of the clinical_study key in your non-documents:
db.test.find({ "clinical_study.#rank" : "379" }, { "_id" : 0, "clinical_study.$" : 1 })
I have been at this for hours. How do you get filtering to work?
None of the solutions online works.
All I want to do is grab the comments(highlighted by these <<<>>>) from the json below from the name “Tori Smith”. I’ve been using this app to test http://jsonpath.curiousconcept.com/.
This is as far as I have gotten: ‘comments.data..from.id’
Data:
{
"id":"12029930209393029_10100748134340048",
"from":{
"id":"12029930209393029",
"name":"Tori Smith"
},
"message":"Buy this now",
"picture":"https:\/\/fbexternal-a.akamaihd.net\/app_full_proxy.php?app=141861192518680&v=1&size=z&cksum=a0471c1f5895cd22c74474fabc989c7e&src=http%3A%2F%2Fmedia3.policymic.com%2FYTM2OWUwN2Q0MSMvRnlpUTkxZU9DMWtGWFZ6TUNiYWh3RkxveXRjPS8yeDE6MTI4Nng2MjIvMTI4MHg2MjAvZmlsdGVyczpxdWFsaXR5KDcwKS9odHRwOi8vczMuYW1hem9uYXdzLmNvbS9wb2xpY3ltaWMtaW1hZ2VzL2JqNTdvbTZxZGd1N3ZpaGtvcWVrNnlzaTI5bW55dGZqanEwMWhuc3FqYjgxc3dkeGcyN2F6czV0eXV0bWJzZTguanBn.jpg",
"link":"http:\/\/mic.com\/articles\/101252\/this-tiny-box-will-let-you-stay-anonymous-on-the-internet",
"name":"This Tiny Box Will Let You Stay Anonymous on the Internet",
"caption":"Mic",
"description":"A simple and elegant solution to a major technology problem.",
"icon":"https:\/\/fbcdn-photos-d-a.akamaihd.net\/hphotos-ak-xpf1\/t39.2081-0\/10333103_752719651432828_1597152122_n.png",
"actions":[
{
"name":"Comment",
"link":"https:\/\/www.facebook.com\/12029930209393029\/posts\/10100748134340048"
},
{
"name":"Like",
"link":"https:\/\/www.facebook.com\/12029930209393029\/posts\/10100748134340048"
}
],
"privacy":{
"description":"Your friends",
"value":"ALL_FRIENDS",
"friends":"",
"networks":"",
"allow":"",
"deny":""
},
"type":"link",
"status_type":"app_created_story",
"application":{
"name":"Mic",
"namespace":"micmediaapp",
"id":"141861192518680"
},
"created_time":"2014-10-14T14:54:54+0000",
"updated_time":"2014-10-15T03:55:19+0000",
"comments":{
"data":[
{
"id":"10100748134340048_10100748984636048",
"from":{
"id":"123094958239849866",
"name":"Don Draper"
},
"message":"Even if I use Tor",
"can_remove":true,
"created_time":"2014-10-15T03:03:29+0000",
"like_count":0,
"user_likes":false
},
{
"id":"10100748134340048_10100749036726658",
"from":{
"id":"12029930209393029",
"name":"Tori Smith"
},
<<< "message":"Yes this can go with you and I think it works for all apps outside of TOR browser", >>>
"can_remove":true,
"created_time":"2014-10-15T03:55:19+0000",
"like_count":0,
"user_likes":false
},
{
"id":"10100748134340048_1010074901234658",
"from":{
"id":"12029930209393029",
"name":"Tori Smith"
},
<<< "message":"Second Text", >>>
"can_remove":true,
"created_time":"2014-10-15T03:55:19+0000",
"like_count":0,
"user_likes":false
}
],
"paging":{
"cursors":{
"after":"WTI5dGJXVnVkRjlqZFhKemIzSTZNVEF4TURBM05Ea3dNelkzTWpZMk5UZzZNVFF4TXpNME5UTXhPVG95",
"before":"WTI5dGJXVnVkRjlqZFhKemIzSTZNVEF4TURBM05EZzVPRFEyTXpZd05EZzZNVFF4TXpNME1qSXdPVG94"
}
}
}
}
To get at the comments you need to introduce a filter expression for filtering to comments by "Tori Smith" and then select the comment field.
Taking it step by step, to get all the comments, you need this:
$.comments.data
Then to filter to only the comments by "Tori Smith" add a filter like this:
$.comments.data[?(#.from.name == 'Tori Smith')]
Finally, to select only the message expand the query like this:
$.comments.data[?(#.from.name == 'Tori Smith')].message
I have tested this using the online JSON query tool here:
http://www.jsonquerytool.com/sample/jsonpathwhereselectcomments