Provide JSON as data for rich:extendedDataTable - json

I am implementing a full text search in my project and for that the result of search comes from SOLR server as JSON.
Is it possible to provide JSON for data or value attribute of the richfaces component extendedDatatTable or simple dataTable.
Resultant JSON would look something like :
`resultObj = {
"numberOfResults":25,
"results":[
{
"instanceId":100,
"inj_Name":"Inj4",
"i_IdentificationNumber":127,
"noz_Name":"Nozzle4",
"n_IdentificationNumber":460,
"thr_Name":"Throttleplate4",
"t_IdentificationNumber":0,
"act_Name":"Atuator4",
"a_IdentificationNumber":781
},
{
"instanceId":100,
"inj_Name":"Inj4",
"i_IdentificationNumber":127,
"noz_Name":"Nozzle4",
"n_IdentificationNumber":460,
"thr_Name":"Throttleplate4",
"t_IdentificationNumber":0,
"act_Name":"Atuator4",
"a_IdentificationNumber":781
} ]
};
`
Regards,
Satya

As far as I know, no you can't. Your best bet would be to reflect this data into a List of Java objects using Gson and then use that list as a data source.

Related

How to save a JSON-object and use it in another request?

i'm currently trying to set up some JMeter testplans. I am pretty new to this (started a week ago) and don't have much programming experience either, so i hope you could help me in this case.
I already set up some http requests and have some simple JSON Extractor post processors to save some of the variables and use them with the "${variable}" notation.
But now i need to save and modify an object from a response to use that in the next http request.
My respose is a extremely big JSON object and the part im interested in looks something like this:
{
"payload": {
"workspace": {
"resultInstance": [
[{"part": "1"...}],
[{"part": "2"...}],
...
[{"part": "20"...}]
]
}
}
}
Note that for whatever reason these objects {"part":"1"...} are inside a nested array. And they are also pretty big.
I would like to safe those objects in a variable to use them in my next http request which should looks like this:
{
"instanceChange": {
"functionChecks": [
{"part": "1"...},
{"part": "2"...},
...
{"part": "20"...}
]
}
}
So what im really trying to find is a way to save all of the possible objects inside the nested array "resultInstance" and put them inside the non nested array "functionChecks".
I already looked inside the JMeter documentation but because of my poor programming background i cant find a way to realize this.
I think i need something like the JSR223 PostProcessor and "simply go through the resultInstance-array and use smth. like an getObject() on these", but i cant figure out the code i need and if its even possible to safe objects in variables in Jmeter.
Im pretty thankful for every bit of help or advice :).
Thanks in advance,
aiksn
Add JSR223 PostProcessor as a child of the request which returns the JSON response
Put the following code into "Script" area:
def response = new groovy.json.JsonSlurper().parse(prev.getResponseData())
def request = ['instanceChange': ['functionChecks': response.payload.workspace.resultInstance]]
vars.put('request', new groovy.json.JsonBuilder(request).toPrettyString())
That's it, you should be able to refer the generated request body as ${request} where required
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
let response ={
"payload": {
"workspace": {
"resultInstance": [
[{"part": "1"...}],
[{"part": "2"...}],
...
[{"part": "20"...}]
]
}
}
};
let requestObj={
"instanceChange": {
"functionChecks": [
]
}
};
response.payload.workspace.resultInstance.forEach(myFunction);
myFunction(item, index) {
requestObj.instance.functionsCheck.push(item[0]);
}

How to parse Json with Array list

I have below response from an API get call.
How do i read the value of dummyId and testcontactId. Below is the sample response:
{
"pageCount":1,
"pageIndex":0,
"pageSize":200,
"totalCount":1,
"dto":{
"data":[
{
"callDuration":"0:00:07",
"dummyId":20,
"testcontactId":"3002",
"id":54
}
],
"columns":[
{
"fieldName":"test1",
"displayName":"test Id",
"show":true,
"sortable":true,
"fieldType":"string",
"order":1
}
]
}
}
I can't place a comment to ask what language you're using, Here is how you'd do it in JavaScript
Parse your API Result to a Object with var data = JSON.parse() JSON.parse()
Then you can just go data.dto.data[0].dummyId
Since dto.data is an array, You can just use the indexes to access each option.
if you need to find specific values, You might want to take a look at Array.find
In the future, Please add a tag with your programming language and things you've tried.

How to parse json format having no array inside it on sencha platform

I am new to sencha so I have to set Data for which i am using this function component.setData( eval(WebServiceUtil.getAPIData('cartPage', 'getCartInfo')))
But when I am printing values inside cartPage.html file on console then I am not getting any json data there. So Can you give any suggestion for this format
I am fetching my json data from getCartInfo.txt file
[
{
"data":{
"unitPrice":56,
"shippingCity":"Mumbai",
"image":null,
"quantity":1,
"productId":"genpr-5",
"storePriceId":"12",
"customerIp":null,
"orderId":"2342",
"trackingCode":null,
"sessionId":"u48m6kn56k_66E4FE42F194803DB16D2692EA9DB608",
"storeId":"STORE-13",
"orderDetailId":null,
"productName":null,
"typeProduct":null,
"totalAmount":56,
"storeInventoryId":"5",
"toCurrency":null,
"inventorySensible":false,
"name":"Samsung Galaxy",
"customerId":"anonymous",
"fromCurrency":null,
"id":"EBEE13831114",
"currencyConversionRate":0,
"currencyCode":null
},
"response":"success"
}
]
I have solved my question by my own. The modification which i have done
is WebServiceUtil.getAPIData('cartPage', 'getCartInfo')[0].data which help ferch data from json.

Uson jsTree with custom JSON structure

I've been searching for ways to do this, but I'm missing something.
I have a custom JSON object, which can basically have any structure, and I want to use this with jsTree. I've found a corresponding plugin here, that claims to have a _parse_json function to transform a custom JSON object to the format that jsTree requires, but for the life of me I can't figure out how to call that plugin. It seems to be included in the version of jsTree that I'm using (1.0rc3).
There is a usage of UIMTreeProcessor I've found, that consists of parsing the XML and calling jsTree like so:
$.jstree._themes = "Content/jstreethemes/";
this.treeEl.jstree({
"json_data" : {
"data":data,
"progressive_render":"true"
},
"plugins" : [ "themes", "ui", "json_data" ],
"core": { "animation": 0 }
});
Now, instead of UIMTreeProcessor parsing the XML and populating data, I want to call $.json_data._parse_json(), but I keep getting errors that this function doesn't exist.
Can anyone show me an example? Thank you kindly.

Nested JSON-response from Magento-REST in Sencha Touch 2's Store

I'm having a hard time using my product-store's proxy on a response coming from magento 1.7
The response looks like this:
{
"1":
{"entity_id":"1","type_id":"simple","sku":"dress_test","status":"1","visibility":"4","tax_class_id":"2","weight":"1.0000","price":"1500.0000","special_price":"1000.0000","name":"Wedding dress","url_key":"dress","country_of_manufacture":"AO","msrp_display_actual_price_type":"2","gift_message_available":"1","news_from_date":"2012-03-21 00:00:00","news_to_date":"2012-03-24 00:00:00","special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"White wedding dress"},
"2":
{"entity_id":"2","type_id":"simple","sku":"black_sunglasses","status":"1","visibility":"4","tax_class_id":"2","weight":"0.2000","price":"500.0000","special_price":"300.0000","name":"Sunglasses","url_key":"sunglasses","country_of_manufacture":"AR","msrp_display_actual_price_type":"2","gift_message_available":null,"news_from_date":null,"news_to_date":null,"special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"Black sunglasses"}
}
But the input expected from sencha (I think) should look like this:
{
{"entity_id":"1","type_id":"simple","sku":"dress_test","status":"1","visibility":"4","tax_class_id":"2","weight":"1.0000","price":"1500.0000","special_price":"1000.0000","name":"Wedding dress","url_key":"dress","country_of_manufacture":"AO","msrp_display_actual_price_type":"2","gift_message_available":"1","news_from_date":"2012-03-21 00:00:00","news_to_date":"2012-03-24 00:00:00","special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"White wedding dress"},
{"entity_id":"2","type_id":"simple","sku":"black_sunglasses","status":"1","visibility":"4","tax_class_id":"2","weight":"0.2000","price":"500.0000","special_price":"300.0000","name":"Sunglasses","url_key":"sunglasses","country_of_manufacture":"AR","msrp_display_actual_price_type":"2","gift_message_available":null,"news_from_date":null,"news_to_date":null,"special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"Black sunglasses"}
}
How can I change the behaviour of the proxy to be able to store the loaded data into my store?
Many thanks in advance!
To customize your own response you have to subclass Ext.data.reader.Reader
Reader or in your case Json class converts data from the response to result set is accepted by Sencha's Model/Proxy/Store.
Cheers, Oleg
add
Ext.define('lib.data.reader.Json', {
extend: 'Ext.data.reader.Json',
alias : 'reader.magentojson', ...
})
than use later reference on the reader: 'magentojson'
and you keep original reference to 'json' reader!