Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm unable to escape the XML charecters in the Json response.
Here is the JSON response
{"projectId":14,"modificationDate":1379677731000,"projectJsonData":"{"playerConfig":{"autoPlay":true,"initVolume":"50","initFullScreen":false,"size":"container","splashPoster":"defailt.png","projectId":123456},"formList":[{"type":"form","subType":"form-image","position":"inscreen","transition":"comealive-fade","width":50,"zindex":998,"start":12.9125390745513,"end":16.90343280291607,"id":"complexForm1","layout":"formTemplate","imgSrc":"images/birds.jpg","title":"Gannets usually found in Australia..","desc":"The birds that you see in this video are Gannets usually found in Australia and New Zealand. Diving birds are birds which plunge into water to catch fish or other food. They may enter the water from flight, as does the brown pelican or they may dive from the surface of the water. More than likely they evolved from birds already adapted for swimming that were equipped with such adaptations as lobed or webbed feet for propulsion.","button":[{"title":"Gannets","action":"http://en.wikipedia.org/wiki/Gannet","type":"link"},{"title":"Aussie Gannet","action":"http://en.wikipedia.org/wiki/Australasian_Gannet","type":"link"},{"title":"Photography","action":"http://aloneatseaphotography.com.au/8950","type":"link"}],"displayType":"non-intrusive","action":"internal-seek"},{"type":"form","subType":"form-video","start":26.9125390745513,"end":35.90343280291607,"target":"video-container","position":"custom","transition":"comealive-fade","id":"complexForm2","layout":"formTemplate","videoSrc":[{"src":"videos/ocean.mp4","type":"video/mp4","codecs":"vp8,vorbis"},{"src":"videos/ocean.webm","type":"video/webm","codecs":"vp8,vorbis"}],"title":"Slow Motion","desc":"Gannets in super slow-mo","button":[],"displayType":"non-intrusive","tags":"Gannets","action":"internal-seek"},{"type":"form","subType":"form-custom","start":4,"end":10,"target":"video-container","position":"custom","id":"complexForm3","layout":"custom","title":"Gannets","content":"%3Cimg%20style%3D%22position%3Aabsolute%3Bright%3A10%25%3Btop%3A20px%22%20width%3D%22150%22%20height%3D%22150%22%20src%3D%22images%2Fbirds.jpg%22%20%2F%3E","displayType":"intrusive-parallel","desc":"Gannets","tags":"Gannets","action":"internal-seek","animation":"slideIn-600-easeOutBounce"}
I have given partial Json response due to size limitation here.
I have used the following to parse the response
JSONObject jsonProjectDataObject = new JSONObject(
StringEscapeUtils.escapeXml(videoGetResponse.get("projectJsonData").toString()));
Now I get the exception as
org.json.JSONException: Expected ':' after " at character 7 of {"playerConfig":{"autoPlay":true,"initVolume":"50","initFullScreen"
JSON is not XML. Using XML entities is not the appropriate way to escape JSON.
Double quote escaped using XML entities: "
Double quote escaped using JSON : \"
Paste your output here it says its invalid json. Before parsing json check this link
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
I am trying to pass a string extracted from an API response in a subsequent call in JMeter. I am able to extract the object I want ("thing": "THING"), store it as variable $thisThing and then pass it, but not as a string.
Using this as my body data:
{
"foo": "bar",
"thing": ${thisThing}
}
...results in this request body:
{
"foo": "bar",
"thing": THING,
}
And the API errors out, unexpected token. Looking into post-processing solutions but I can't dig up anything of relevance.
As per JSON Object Literals:
Keys must be strings, and values must be a valid JSON data type:
string
number
object
array
boolean
null
so if this THING supposed to be a JSON String - you need to surround it with quotation marks:
{
"foo": "bar",
"thing": "${thisThing}"
}
or amend your Post-Processor configuration to extract the THING value along with surrounding quotation marks.
You might also need to add a HTTP Header Manager and configure it to send Content-Type header with the value of application/json
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a Stack Overflow question where I'm attempting to use Jython to extract a field value from JSON text:
Jython: Parse JSON object to get value (using Java functions)
A Stack Overflow community member has been kind enough to point me towards some Java documentation:
IBM >> Maximo >> Class JSONObject (Java)
Unfortunately, I've been staring at the Java documentation page for hours now, and to be honest, I have absolutely no idea what I'm looking at.
Where does this documentation show me how to extract a value from JSON text?
In other words, how do interpret this cryptic Java class documentation?
Start here, by passing the JSON string into the parse function.
Then, once you have your JSONObject, you can traverse the tree treating the object as a HashMap.
String jsonInput = "{ 'foo':'bar' }";
JSONObject jsonObject = JSONObject.parse(jsonInput);
String fooValue = jsonObject.get('foo');
Of course, this is the hard way. You might consider a more fluid library like JsonPath, which also has documentation that's more fluid.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
[
{
"firstName":"Ivan",
"lastName":"Petrov",
"birthDate":"1993-03-09",
"email":"kazakhsam",
"address":{
"country":"Russia",
"city":"Moscow",
"street":"Lenin",.
"buildingNo":"10"
}
}
]
It gives me this error:
org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
Thanks in advance.
Your JSON is not valid. You have an extra dot character after "Lenin",.
Cou can validate you JSON String with online validators, I suggest you to use this one: https://jsonformatter.curiousconcept.com/
If you paste your JSON there then it tells excatly what is wrong with your json string:
Error:Strings should be wrapped in double quotes.[Code 17, Structure
34]
Error:Invalid characters found.[Code 18, Structure 34]
Use jsonlint.com to check for correct indentation.
This is a json array not json object try to parse array object.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
this is my first post here. I'm taking my first class in Java and I have come across a question which I believe is a trick question. I know that reserved words can't be used as identifiers and identifiers are only supposed to use upper/lowercase letters, 0-9, $, and _. long is a reserved word, but would using LONG be ok since Java is case sensitive? I have looked all over google for the answer for this. I could not find an answer on stack overflow so sorry if this is answered elsewhere on the forum!
Thanks!
I think you may have figured out by yourself that reserve words are also case sensitive when you say that Java is case sensitive.
Using LONG as identifier would not cause any problem for the Java compiler, but the problem is variable name LONG may not mean much and might not contribute to a readable code
The compiler will allow you to use LONG as an identifier.
Your fellow programmers, however, will try to hold you back.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
<pko:POImport xmlns:xs="http://XMLSchema-instance"
xmlns:pko="hello"
xs:schemaLocation=" PlannedQuantityImport.xsd" tag="TAG" notes="These are my notes" totalqtypctmin="2" totalqtypctmax="3" mismatchthresholdpct="8.0">
<prodgrp id="100067">
<prodid>SYC87948427320</prodid>
<locgrp id="100067">
<geoid>30454</geoid>
<geoid>30982</geoid>
<quantity date="2010-12-11" sequence="1" prodid="87948427320">600</quantity>
</locgrp>
</prodgrp>
</pko:POImport>
I want to get the data corresponding to
tag, notes,totalqtypctmin,totalqtypctmax,mismatchthresholdpct,prodgrp,prodid,locgroup,geoid etc.
You will need XML parser to extract information from a XML using your desired xPath. Refer to this Best XML parser for Java.
I'd just use string matching.
inputStream = new BufferedReader(new FileReader("file.xml"));
while(inputStream.hasNext()){
String s=inputStream.next();
if(s.indexOf("totalqtypctmax")==-1)
continue;
String k = s.split("totalqtypctmax=\"")[1].split("\"")[0];
System.out.println("The value of totalqtypctmax is "+k);
}
Java isn't my first language, so pardon any silly mistakes.
EDIT: The only reason I'm using string matching instead of a standard XML parser, which is obviously recommended for more elaborate XML files, is because, in this case, your requirements seem very specific.
Their are various methods for parsing in java you could either use
DOM parsing
SAX parsing
These are included in the JDK by default
you can also use JDOM
Goto the following link to more info
http://www.mkyong.com/tutorials/java-xml-tutorials/