I have a bit of code that has been working for years
JSONObject variableData = new JSONObject(request.getParameter("VARIABLE_DATA"));
JSONArray companies = variableData.getJSONArray("COMPANIES");
and today, I get the following error:
JSONObject["COMPANIES"] is not a JSONArray.
I have stopped the code prior to executing the getJSONArray() call and looked into variableData. Here is what I find:
{"COMPANIES":[{"COMPANY":"2"}]}
To me, this looks like a valid JSONArray to be pulled from a valid JSONObject, so I'm flummoxed and looking for help. Thanks.
your piece of code works fine when using org.json-20120521.jar. I think there is something wrong with the jar you are using.
But "COMPANIES":[{"COMPANY":"2"}] is not a valid json. Other question that I would ask is the exception reproducible? Did you get this data from exact same request that produced the exception? Is there a chance that your server got corrupted data? Try to write a unit test that covers this case and check were it takes you.
Related
I am using FME to get output from the following: https://coronavirus.data.gov.uk/developers-guide
I am just a beginner and is first time I want to write this up. To generate an Output URL from this with the relevant columns, can anyone explain what I need to get the request URL. I am using GET as the HTTP method
An example of a url i get some data out of is - https://soa.smext.faa.gov/asws/api/airport/status/SFO
But when i try with the links below which i tested does not get any output https://api.coronavirus.data.gov.uk/v1/data?filters=areaType=nation;areaName=england&structure=%7B%22name%22:%22areaName%22%7D
https://api.coronavirus.data.gov.uk//v1/data?filters=areaType=nation;areaName=england&structure={"date":"date","areaName":"areaName","areaCode":"areaCode","newCasesByPublishDate":"2020-07-07","cumCasesByPublishDate":"2020-08-08","newDeathsByDeathDate":"2020-02-06","cumDeathsByDeathDate":"2020-06-09"}
This is a better link for you to try out.
https://api.coronavirus.data.gov.uk/v1/data?filters=areaType=nation;areaName=england&structure={%22date%22:%22date%22,%22areaName%22:%22areaName%22,%22areaCode%22:%22areaCode%22,%22newCasesByPublishDate%22:%22newCasesByPublishDate%22,%22cumCasesByPublishDate%22:%22cumCasesByPublishDate%22,%22newDeaths28DaysByDeathDate%22:%22newDeaths28DaysByDeathDate%22}
Took me a while to suss it out.
i am trying to parse the following json file in java with gson:
So , I am trying to retrieve only the issues into a list of Issue. I have the following class to store the issue information:
But i got an error.. I am trying to get with the following but I think that i am so lost with this ( i am learning about this ) and i dont understand the error
any idea of how to do this? thank you so much!
obj.get("issues")
will actually return a List Object, and not an Issue Object. You need to change the second parameter accordingly.
I´m creating a table using iText.
But the output looks really bad, because of the hyphenation, which seems not to be done properly.
I allready read this question How to hyphenate text?
and this example http://itextpdf.com/sandbox/tables/HyphenationExample
I tried the example in eclipse after i added the itext_hyph_xml.jar to my class path. No error is thrown when i run the code, but the lines
Hyphenator h = new Hyphenator("de", "DE", 2, 2);
Hyphenation s = h.hyphenate("Leistungsscheinziffer");
System.out.println(s);
print null to the console instead of "Lei-stungs-schein-zif-fer" or something similar as i expected.
I tried playing with the parameters in
chunk.setHyphenation(new HyphenationAuto("de", "DE", 2,2));
but the output in the document never differes even slightly.
The code i´m trying to get to work looks kind of like this by the way:
for(String s: interest){
Chunk chunk = new Chunk(s,FONT[0]);
chunk.setHyphenation(new HyphenationAuto("de", "DE", 2,3));
table.addCell(new Phrase(chunk));
}
Ok I figured it out on my own now.
And because i couldn´t find the answer on the internet i thought i will share it here so anyone who might have the same error in the future wouldn´t need a week to figure it out.
It seems that in the class Hyphenator the defaultHyphLocation is set like this:
private static final String defaultHyphLocation = "com/itextpdf/text/pdf/hyphenation/hyph/";
But the structure of itext_hyph.jar looks like this:
com.lowagie.text.pdf.hyphenation.hyph
Obviously loading a hyph file from the jar will surely fail, since the path used by Hyphenator can not be found. I actually thought this would cause an error but it seems simply null is returned when the loading of the hyph file fails.
Calling Hyphenator.setHyphenDir("com/lowagie/text/pdf/hyphenation/hyph/"); however wouldn´t change a thing as one would think, since it changes the wrong string variable.
The only thing i could think of to solve this problem was to recreate the itext_hyph.jar according to the path given in Hyphenator and that acctually fixed it. Hyphenation is now working.
Hie everybody, i am trying to make a PictureSymbolMarker in my arcgis map..
However i am facing some problems in it. i went to esri website [ http://blogs.esri.com/esri/arcgis/2012/02/03/esri-picture-marker-symbol-generator-for-javascript-developers/ ] to get a pin url .
When i tried to implement it in my codes,
i received error .
This is how i put it together
From
`//Marker
SimpleMarkerSymbol resultSymbol = new SimpleMarkerSymbol(Color.RED,
20, SimpleMarkerSymbol.STYLE.CIRCLE);`
To
`SimpleMarkerSymbol resultSymbol = new SimpleMarkerSymbol
({"angle":0,"xoffset":0,"yoffset":12,"type":"esriPMS",
"url":"http://static.arcgis.com/images/Symbols/Basic/RedStickpin.png",
"contentType":"image/png","width":24,"height":24});`
But after implementing that codes, i received errors. .. Anybody have face the same problem and are enable to troubleshoot it?
Thanks in Advance
your issue is that you are using JSON for a PictureMarkerSymbol and initializing a SimpleMarkerSymbol which will never work. Try to do like this.
var resultSymbol = new esri.symbol.PictureMarkerSymbol
({"angle":0,"xoffset":0,"yoffset":12,"type":"esriPMS",
"url":"http://static.arcgis.com/images/Symbols/Basic/RedStickpin.png",
"contentType":"image/png","width":24,"height":24});
You're using JavaScript object notation (JSON) syntax in your Java code for Android. It won't work.
#azmuhak is on the right track though. You need to create a PictureMarkerSymbol instead of a SimpleMarkerSymbol. But you need to do it the Android way, not the JavaScript way.
Here's some sample code for creating a PictureMarkerSymbol, creating a GraphicsLayer, adding the GraphicsLayer to the map, and adding a new Graphic to the GraphicsLayer (run this code after the map is loaded, maybe using MapView.setOnStatusChangedListener):
PictureMarkerSymbol pms = new PictureMarkerSymbol(
"http://static.arcgis.com/images/Symbols/Basic/RedStickpin.png");
pms.setAngle(0f);
pms.setOffsetX(0f);
pms.setOffsetY(12f);
GraphicsLayer graphicsLayer = new GraphicsLayer();
mMapView.addLayer(graphicsLayer);
graphicsLayer.addGraphic(new Graphic(new Point(12, 34), pms));
Side note: it is possible in Android to parse a JSON string to make a PictureMarkerSymbol. But in this case, my sample code is easier and less error-prone.
When updating OCPsoft Rewrite from Version 1.0.5.Final to 1.1.0.Final the following Rule no longer works and I don't know how to fix it:
.addRule(
Join.path("/{i}/{d}")
.where("i").matches("[-_a-zA-Z0-9~*]{8}")
.where("d").matches("[-_a-zA-Z0-9~*]{32}")
.to("/resources/html/user/doSomething.html?i={i}&d={d}")
)
In the Rewrite changelog there is one point that could help you help me:
Configuration strings are now literal. Regular expressions must be configured through a >parameter such as: .defineRule().when(Path.matches("/{*}").where("*").matches(".*"))
The exception I get is the following one:
Exception starting filter OCPsoft Rewrite Filter
java.lang.NullPointerException
at org.ocpsoft.rewrite.servlet.config.rule.Join.where(Join.java:199)
at org.ocpsoft.rewrite.servlet.config.rule.Join.where(Join.java:47)
at com.myapp.util.RewriteConfigurationProvider.getConfiguration(RewriteConfigurationProvider.java:39)
...
The following did the trick, I just had to reorder the join clauses:
.addRule(
Join.path("/{i}/{d}")
.to("/resources/html/user/doSomething.html")
.where("i").matches("[-_a-zA-Z0-9~*]{8}")
.where("d").matches("[-_a-zA-Z0-9~*]{32}")
.withRequestBinding();
)
Thanks to Lincoln, who figured this out and answered my question on the Rewrite support forums.
Hmm.. that does look like a bug, I'll try to reproduce this, but you shouldn't need to re-define {i} and {d} in the target URL. Join will handle that for you automatically if you use request binding, like so:
.addRule(
Join.path("/{i}/{d}")
.where("i").matches("[-_a-zA-Z0-9~*]{8}")
.where("d").matches("[-_a-zA-Z0-9~*]{32}")
.to("/resources/html/user/doSomething.html").withRequestBinding();
)
I'm guessing if you do that, your problem will go away. You can also use .withInboundCorrection() if you'd like to redirect requests for the old .html URL to the new URL.
If you still have a problem with this, please post on the support forums and we'll get it figured out :)
Sorry you had trouble, hopefully it won't be trouble any more :)