JSON Parsing Query in AS3 - json

I'm creating an application that uses a License Plate Recognition System.
The API that I'm using is rest based and returns a JSON to my application, a JSON which I parse and which basically looks like this:
{"plate":
{"data_type": "alpr_results", "epoch_time": 1469660951857, "img_height": 288, "img_width": 432, "results":
[{"plate": "MBR527D", "confidence": 88.891518.....
This is what my parse looks like when I load it into Actionscript:
var ThePlate:Object = JSON.parse(e.target.data)
The Issue I'm having is that I'm unable to trace the Plate entitled "MBR527D" within results, basically because I'm a noob when it comes to JSON.
This is what I try when I attempt to trace the plate and I know I'm doing something wrong:
trace(ThePlate.results.plate);
It returns "undefined", however when I try to trace the image height:
trace(ThePlate.img_height);
It returns the 288 just fine, so I know I'm making a basic error but would appreciate any help you guys have! Thanks!

I'm unable to trace the Plate entitled "MBR527D" within results
That's because it's not (directly) in it. results is an array, which has an object as first element, which has a property named "plate" which has the desired value:
"results": [{"plate": "MBR527D",
trace(ThePlate.results.plate);
Try
trace(ThePlate.results[0].plate);
instead.

Related

Accesing Json data after 'loading' it

With a lot of help from people in this site, I managed to get some Json data from an amazon page. The data, for example, looks like this.
https://jsoneditoronline.org/?id=9ea92643044f4ac88bcc3e76d98425fc
First I have a list of strings which is converted to a string.
script = response.xpath('//script/text()').extract()
#For example, I need the variationValues data
variationValues = re.findall(r'variationValues\" : ({.*?})', ' '.join(script))[0]
Then, in my code, I have this (not a great name, will be changed later)
variationValuesJson = json.loads(variationValues)
variationValuesJson is in fact a dictionary, so doing something like this
variationValues["size_name"][3]
Should return "5.5 M US"
My issue is that, when running the program, I get the string indices must be integers error. Anyone knows whats wrong?
Note: I have tried using 'size_name' instead of "size_name", same error
variationValues["size_name"][3] #this is the raw string which you have converted to variationValuesjson
I think this is not what you actually want.
Your code should be this.
variationValuesJson['size_name'][3] #use variationValuesjson ;)

Jmeter CSV issue

Please help me with following issue:
I have a simple Jmeter test with where variables are stored in CSV file. There is only one request in the test:
Get .../api/${page} , where ${page} is a variable from CSV
Everything goes well with thread properties for ex. 10 threads x30 loop count
If i increase any parameter, for ex. in 10x40 or 15x30, i receive at least one error and looks like this is jmeter issue:
one request (random) isn't able to take variable from CSV and i got an error:
-.../api/page returns 404 error
So the question is - is there any limit in jmeter's connection to CSV file?
Thanks in advance.
A key point to focus on is the way your application manage the case when 2 different users require the same page.
There are few checks that I would recommend:
be sure that the "Recycle on EOF" property is true
be sure that you have more lines on CSV than the number of threads you are firing
use a "View result tree" controller to investigate the kind of error you are getting
Let us know

parsing JSON nested input in Scalding

I have some JSON input that I need to parse and process (this is the first time I am using JSON). My input is as follows:
{"id":"id2","v":2, "d":{"Location":"JPN"})
{"id":"id1","v":1, "d":{"Location":"USA"}}
{"id":"id2","v":1, "d":{"Location":"JPN"}}
{"id":"id1","v":2, "d":{"Location":"USA"}}
My goal is to write a scalding script that groups the input by the Location field and output the count. SO in the above example, "JPN" and "USA" should have a count of 2 each.
Scalding provides a class called JsonLine. My script is as follows:
class ParseJsonLine(args: Args) extends Job(args) {
JsonLine(args("input"), ('id, 'v, 'd)).read
.groupBy('d){_.size}
.write(args("output"))
}
The above code compiles ok, but at runtime generates the following error:
Caused by: java.lang.ClassCastException: scala.collection.immutable.Map$Map1 cannot be cast to java.lang.Comparable
Basically, I am not sure how to reference the Location field. "d.Location" did not work and grouping by the complex structure "d" produces the arity error above.
I did not find too many examples of nested input parsing using json in scalding. Also, I am not sure if there is something better than JsonLine for nested input.
I would appreciate your help.
thanks
Perhaps using Symbol?
Take a look at the unit tests: https://github.com/twitter/scalding/blob/0.11.0/scalding-json/src/test/scala/com/twitter/scalding/JsonLineTest.scala
JsonLine(args("input"), ('id, 'v, Symbol("d.Location"))).read
.groupBy(Symbol("d.Location")){_.size}
.write(args("output"))
Note: Learner here so feel free to improvise/correct/educate.

How do I work around cases where the listProvider data comes back as just ONE single record?

Im using HTTPservice to load XML and show the results in a list - it works when there are more than 1 XML record found.... but when there is only ONE single returned XML record it gets treated differently for some reason and generates this error:
Suspended: TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy
I see posts like this:
http://anupushkaran.blogspot.com/2010/02/typeerror-error-1034-type-coercion.html
but I cant figure out how to adapt it to my HTTPService resultHandler code block...
Im using FB 4.6 and my XML structure looks like the following:
SiteXYZ
Events
EventListing
and all the data I want to use is under the EventListing Node.
I've tested some code that can detect when the length of whats returned so I think I can just detect when the length is 1 and then handle something differently -- not sure what though.
Another thing Im seeing that I think gets me close... when I look at the network monitor's TreeView > Response > Response Body I can see that on a succesful trip, the body comes back like:
SiteXYZ
Events
EventListing
[0]
[1].... and so on....
But on the cases where its a SINGLE record returned, the body of the response comes back like:
SiteXYZ
Events
EventListing
so shouldnt I be able to detect when its just ONE returned record and then set the list dataProvider accordingly? so that when its a lot of returned records the dataprovider is set with:
list1.dataProvider = myXML.lastResult.SiteXYZ.Events.EventListing;
but when its just ONE returned record, how would that dataProvider be set? this didnt work:
list1.dataProvider = lfXML.lastResult.LeisureFun.Events;
can anyone help with this? is my approach way off base? sorry for the rambling nature of the question but as I typed it, I stopped about 5 times and tried a number of things that came to mind as I thought through it... still nothing worked though... I feel like Im onto something (could be wrong though) but just cant solve it yet.
Answer was in the original website I referenced....
i took a closer look at what that post said the problem presented was and how that code snippet addressed it and was able to get it to work for me by putting it in my resultHandler block...
arr=new ArrayCollection();
if(event.result.SiteXYZ.Events.EventListing is ArrayCollection)
{
arr = ArrayCollection(event.result.SiteXYZ.Events.EventListing);
}
if(event.result.SiteXYZ.Events.EventListing is ObjectProxy)
{
arr =new ArrayCollection(ArrayUtil.toArray
(event.result.SiteXYZ.Events.EventListing));
}
now when there is one record returned it shows fine... same for multiple records returned.
thanks for the help though... I'll definately save this snippet for future use!

Vaadin edit json response

Im using Vaadin as the framework to represent a presentation layer for my application.
I have a trouble with the Vaadin Table listing. I load 1000 rows with 5 columms (yes I need to load all 1000, there is also an option to load less. =)) but this is not very fast when using Vaadin. When I look at the Json sent I realize that there are lots of variables that i dont whant to be sent for everu table row.
This is the response i have as of now:
"domaindom-000000938.co_uk",
["17",
{"id": "PID783","readonly":true,"locale": "en_EN","format": "yyyy-MM-dd","strict":true,"wn":false,"parsable":true,
"v":{"day":7,"month":2,"year":2011}}],
["17",
{"id": "PID784","readonly":true,"locale": "en_EN","format": "yyyy-MM-dd","strict":true,"wn":false,"parsable":true,
"v":{"day":7,"month":2,"year":2011}}],
["17",
{"id": "PID785","readonly":true,"locale": "en_EN","format": "yyyy-MM-dd","strict":true,"wn":false,"parsable":true,
"v":{"day":7,"month":2,"year":2012}}],
"","","ENG"],
["tr",{"key":206},"
I would like to transform this Json to be more like
"domaindom-000000938.co_uk",
["17",
{"id": "PID783","locale": "en_EN",,"strict":true,"wn":false,"v1":"2011-07-02", "v2":"2011-02-07", "v3":"2012-02-07"}],
As you can see I have removed a couple of variables and inserted the date varialble in the same clauses.
So my quiestion is this. In Vaadin, how do I modify the way Vaadin creates the Json response? I currently use the BeanItemContainer to hold my objects like this:
public BeanItemContainer getPagedDataSource(){
List<Object> mylist = DAO.getDAO().createQuery(query, index, max);
return new BeanItemContainer<Object>(type, mylist);
}
Thanks for any help or feedback!
/Marthin
First, that JSON is part of Vaadin's internal communication and you should not modify it. However, if you wish to check it out, it is the JsonPaintTarget along with the paintContent-method of the component in question (the Table) that creates the JSON.
Vaadin today operates in an unprecedented way. Everything will change in the application must be sent to the client. On the client side, each component is treated separately and therefore the response must address all components changed.
Each row in the table is a separate component because the answer is so long.
My proposed solution:
write your own implementation of the table - hard
the imposition of restrictions - easy, but it's prosthesis