swiftyjson bundled file not parsing - swifty-json

I've validated the coding and everything works up until I get to the actual parsing function I am unsure as to why I am not able to get any of the values in the array of the json file. I have tried multiple methods of getting every object in the array specified string and still nothing. This is the example code I have.
[ { "Attack": 4, "Card Description": "<b>Deathrattle</b>Deal 2 damage to ALL other characters.", "Card Type": "0", "Class": "10", "Cost": 5, "Health": 4, "Name": "Abomination", "Rarity": 3 },
{ "Class": "1", "Name": "Fiery War Axe", "Cost": 2, "Card Type": 2, "Card Description": "", "Rarity": 5 }, ]

If you use:
json["array"].array
Your JSON must look like:
{
"array": [
{
"Attack": 4,
"Card Description": "DeathrattleDeal 2 damage to ALL other characters.",
"Card Type": "0",
"Class": "10",
"Cost": 5,
"Health": 4,
"Name": "Abomination",
"Rarity": 3
},
{
"Class": "1",
"Name": "Fiery War Axe",
"Cost": 2,
"Card Type": 2,
"Card Description": "",
"Rarity": 5
}
]
}
Because "array" is a key for an array.
Then you can use: (json is your JSON Array)
for obj in json["array"] {
println(obj["Name"].stringValue)
}

Related

OData - How to filter on child elements?

We have an endpoint where the payload looks like this:
{
"#odata.context": "http://localhost/AbcWebApi/v1.0/-/ABC/AP/$metadata#APDistributionSets/$entity",
"DistributionSetKey": "CC",
"Description": "Credit cards",
"Status": "Active",
"InactiveDate": null,
"DateLastMaintained": "2010-08-18T00:00:00Z",
"CodeType": "Purchase",
"DistributionMethod": "Manual",
"DistributionsEntered": 3,
"Currency": "CAD",
"DistributionSetDetails": [
{
"DistributionSet": "CC",
"LineNumber": 1,
"DistributionCode": "VISA",
"Description": "VISA card",
"GLAccount": "1022",
"Discountable": "Yes",
"Percentage": 0,
"Amount": 0,
"UpdateOperation": "Unspecified"
},
{
"DistributionSet": "CC",
"LineNumber": 2,
"DistributionCode": "MASTER",
"Description": "Mastercard",
"GLAccount": "1023",
"Discountable": "Yes",
"Percentage": 0,
"Amount": 0,
"UpdateOperation": "Unspecified"
},
{
"DistributionSet": "CC",
"LineNumber": 3,
"DistributionCode": "AMEX",
"Description": "American Express",
"GLAccount": "1021",
"Discountable": "Yes",
"Percentage": 0,
"Amount": 0,
"UpdateOperation": "Unspecified"
}
],
"UpdateOperation": "Unspecified"
}
Basically, there is a DistributionSetKey called CC. And under CC, there are different child elements like VISA, AMEX, MC, etc. Can I filter by VISA which is the DistributionCode?
This is what I have tried:
http://localhost/AbcWebApi/v1.0/-/ABC/AP/APDistributionSets?$filter=(DistributionSetDetails/DistributionCode eq 'VISA')
And this is the error I'm getting:
"The parent value for a property access of a property 'DistributionCode' is not a single value. Property access can only be applied to a single value."
Any advice? Thanks.

How to get data by query builder in laravel

I use join in query builder and here is the output
[
{
"id": 7,
"name": "class 1",
"idSubject": 17,
"nameSubject": "Math"
},
{
"id": 7,
"name": "class 1",
"idSubject": 16,
"nameSubject": "history"
},
{
"id": 8,
"name": "class 2",
"idSubject": 15,
"nameSubject": "Computer"
},
{
"id": 8,
"name": "class 2",
"idSubject": 19,
"nameSubject": "geography"
}
]
You can see id and name of class 1, 2 appearing twice. So, how to make it appear once.
this is my query:
$data = DB::table('class')->join('class_subject','class.id','=','class_subject.class_id')
->join('subject','class_subject.subject_id','=','subject.id')
->select('class.id','class.name','subject.id as idSubject','subject.name as nameSubject') ->get();
I want it:
[
{
"id": 7,
"name": "class 1",
"subject": [{"idSubject":"17","nameSubject: "Math"},
{"idSubject":"16","nameSubject: "history"}]
}
]
The distinct method allows you to force the query to return distinct results:
Try this
$data = DB::table('class')->join('class_subject','class.id','=','class_subject.class_id')
->join('subject','class_subject.subject_id','=','subject.id')
->select('class.id','class.name','subject.id as idSubject','subject.name as nameSubject')->distinct()->get();

Orbeon: Static dropdown in repeated grid

I have a problem in repeated grid, I have a drop-down list where the users will choose what model they want.
Then I also have a JSON array which contains the model and other description of different cars.
How can I auto fill the appropriate JSON value to textField according to the chosen value in the drop-down list?
Like for example: The user chose the model Toyota, only the Toyota car model present in the JSON will be displayed at textField.
The form I've created is available at https://demo.orbeon.com/demo/fr/orbeon/builder/edit/3b1ebd5340007f245b34ccd468c36c188b376bd6. And here is the JSON:
{
"corppassUser": {
"corppassData": null,
"corppassEntity": {
"primaryActiviyDesc": "Marine insurance ",
"companyType": "A1",
"corppassPreviousNames": [],
"entityType": "LC",
"primaryActivityCode": "65121",
"businessExpiryDate": "",
"secondaryActivityCode": "93202",
"corppassShareholders": [
{
"allocation": 20000,
"personRef": {
"personName": "ANDY",
"nationality": "SG",
"id": 8,
"idno": "S6001111A"
},
"currency": "SGD",
"id": 3,
"entityRef": null,
"category": "1",
"shareType": "1"
},
{
"allocation": 10000,
"personRef": {
"personName": "TIMOTHY TAN",
"nationality": "SP",
"id": 6,
"idno": "S1112374E "
},
"currency": "SGD",
"id": 1,
"entityRef": null,
"category": "1",
"shareType": "1"
},
{
"allocation": 10000,
"personRef": {
"personName": "CLARISSA LIN",
"nationality": "SG",
"id": 7,
"idno": "S3212386E"
},
"currency": "SGD",
"id": 2,
"entityRef": null,
"category": "1",
"shareType": "1"
}
],
"uen": "T15LP0005A"
},
"id": 1
}
}

Elasticsearch Nest Getting and updating a single Document

I would like to be able to select a single document here is a sample of how a document looks
{
"_index": "myindex_products",
"_type": "product",
"_id": "8Wct9mEBlkDZwzEMRfbG",
"_version": 1,
"_score": 1,
"_source": {
"productId": 5749,
"name": "Product Name Here",
"productCode": "PRODCODE",
"productCategoryId": 73,
"length": 6,
"height": 0,
"productTypeId": 1,
"url": "product-name-here",
"productBrandId": 7,
"width": 0,
"dispatchTimeInDays": 10,
"leadTimeInDays": 6,
"stockAvailable": 0,
"weightKg": 0.001,
"reviewRating": 5,
"reviewRatingCount": 17,
"limitedStock": false,
"price": 16.3,
"productImage": "28796-14654.jpg",
"productCategory": {
"productCategoryId": 73,
"name": "Accessories - New",
"fullPath": "Accessories - New",
"code": "00057"
},
"productSpecification": [
{
"productSpecificationId": 127151,
"productId": 5749,
"specificationId": 232,
"name": "Brand",
"value": "Brand1"
}
,
{
"productSpecificationId": 127175,
"productId": 5749,
"specificationId": 10,
"name": "Guarantee",
"value": "10 years"
}
]
}
}
_id is being generated when I index so I don't know this at the point I want to update. I have the productId value and I would like to use this to select a document to then update/delete is there a way to return a single document if you know a particular exact value.
Thanks
While indexing, you can use something like PUT your_index/5749 (5749 being your product id) and ES will use its value for the _id field instead of auto-generating it.

Configuring line charts with remote data in Kendo UI

I am looking to render a line chart using Kendo UI. http://demos.telerik.com/kendo-ui/line-charts/remote-data-binding
It expects the json data to be directly an array like in the format (from their example):
[
{
"date": "12/30/2011",
"close": 405,
"volume": 6414369,
"open": 403.51,
"high": 406.28,
"low": 403.49,
"symbol": "2. AAPL"
},
{
"date": "11/30/2011",
"close": 382.2,
"volume": 14464710,
"open": 381.29,
"high": 382.276,
"low": 378.3,
"symbol": "2. AAPL"
}
]
However, I have a URL that returns the data in the following format. Note the extra object 'ranks' at the beginning which has the array:
{
"ranks": [
{
"id": 2,
"rank": 3,
"rankdate": "2015-05-17T00:00:00+0000",
"student": {
"id": 203,
"name": "Student1",
"currentRank": 3,
"LastVerified": "2015-05-17T22:30:00+0000"
}
},
{
"id": 1,
"rank": 4,
"rankdate": "2015-05-16T00:00:00+0000",
"student": {
"id": 203,
"name": "Student1",
"currentRank": 3,
"LastVerified": "2015-05-17T22:30:00+0000"
}
}
]
}
I was wondering if there was a way to have the datasource look inside "ranks" for the array instead of expecting it directly.
Found it. One can customize the schema in Kendo for the datasource using:
schema: {
data: "ranks"
},

Resources