Accessing values in JSON response - error generated - json.JSON.typeMismatch(JSON.java:100)



I have the following response:


{
"data": [
{
"name": "This is a test 123",
"start_time": "2013-12-02T18:00:00+0530",
"end_time": "2013-12-02T20:00:00+0530",
"location": "Mount Lavinia",
"id": "525447507473743",
"rsvp_status": "attending"
},
{
"name": "This is a test event",
"start_time": "2013-12-02T18:00:00+0530",
"end_time": "2013-12-02T20:00:00+0530",
"location": "Mount Lavinia",
"id": "560383743988530",
"rsvp_status": "attending"

Related to : Accessing values in JSON response - error generated - json.JSON.typeMismatch(JSON.java:100)
Accessing values in JSON response - error generated - json.JSON.typeMismatch(JSON.java:100)
Programming Languages

I have the following response:


{
"data": [
{
"name": "This is a test 123",
"start_time": "2013-12-02T18:00:00+0530",
"end_time": "2013-12-02T20:00:00+0530",
"location": "Mount Lavinia",
"id": "525447507473743",
"rsvp_status": "attending"
},
{
"name": "This is a test event",
"start_time": "2013-12-02T18:00:00+0530",
"end_time": "2013-12-02T20:00:00+0530",
"location": "Mount Lavinia",
"id": "560383743988530",
"rsvp_status": "attending"

remove unwanted ' ' from json values with html tags , generated using amazonaws json toolkit
Programming Languages

I use amazonaws library[com.amazonaws.util.json] (java) for generate json .
I use something as follows


private static final String boldHtmlOpenTag = "<b>";
private static final String boldHtmlCloseTag = "</b>";
private static final String italicsHtmlOpenTag = "<i>";
private static final String italicsHtmlCloseTag = "</i>";
String result = boldHtmlOpenTag + "hello" + boldHtmlCloseTag;
jsonobj.put("test",result);

I get the response as {"test" : <b> hello</b>}.
I need output as without the .
Thanks in advance.


Json: How to extract inner Json objects from a single outer Json object using java
Programming Languages

I have the following Json string, resulting from a google search query:


{"responseData":{"results":[{"region":"IL","streetAddress":"1611 South Randall Road","titleNoFormatting":"Brunswick Zone XL Randall Road","staticMapUrl":"http://maps.google.com/maps/api/staticmap?maptype=roadmap&format=gif&sensor=false&size=150x100&zoom=13&markers=42.162958,-88.334155","listingType":"local","addressLines":["1611 South Randall Road","Algonquin, IL"],"lng":"-88.334155","phoneNumbers":[{"type":"","number":"(847) 658-2257"}],"url":"http://www.google.com/maps/place?source=uds&q=brunswick+zone&cid=8286591317090502839","country":"United States","city":"Algon
Struts2 :: JSON plugin :: give json error response
13/1/2015 10:00 am Programming Languages

I started implementing a simple api key validation for my service. I want to return a json error as a response when an interceptor tells me to.

It doesn't seem to work as expected. Here's what I'm doing:

AuthInterceptor.java:

public class AuthInterceptor extends AbstractInterceptor
implements Interceptor
{
    public String intercept(ActionInvocation invocation) throws
Exception {

        HttpServletRequest request =
ServletActionContext.getRequest();
        String apiKeyHeader = request.getHeader("api_key");

        if (null == apiKeyHeader) {
            throw new Exception("NO API KEY SUPPLIED");
        }

        ApiKeyController apiKeyController = new ApiKeyController();

        try {
            ApiKey apiKey = apiKeyController.findByKey(apiKeyHeader);
        } catch (NotFoundException e) {
            // redirect to error
            return "error";
            // throw new Exception("API KEY INVALID");
        }

        return invocation.invoke();
    }

    public void destroy() {}

    public void init() {
        // TODO: use the logger instead of System.out
        System.out.println("Initializing AuthInterceptor...");
    }
}

In the case where the api key is invalid, I'm assuming I can just invoke a different action that contains all the information needed for that error to be displayed. /service/error.json is a valid url that works, but sadly the redirect of the invocation doesn't.

struts.xml:

<bean
type="org.apache.struts2.rest.handler.ContentTypeHandler"
name="jackson"
class="org.apache.struts2.rest.handler.JacksonLibHandler"/>
<constant name="struts.rest.handlerOverride.json"
value="jackson"/>

<constant name="struts.enable.DynamicMethodInvocation"
value="false"/>
<constant name="struts.devMode" value="true"/>
<constant name="struts.rest.content.restrictToGET"
value="false"/>
<constant name="struts.rest.defaultExtension" value="json"/>
<constant name="struts.rest.handlerOverride.EXTENSION"
value="json"/>
<constant name="struts.i18n.encoding" value="UTF-8"/>

<constant name="struts.action.extension"
value="xhtml,,xml,json,action"/>
<constant name="struts.mapper.class"
value="org.apache.struts2.dispatcher.mapper.PrefixBasedActionMapper"
/>
<constant name="struts.mapper.prefixMapping"
value="/receipt:rest,:struts"/>

<constant name="struts.convention.action.suffix"
value="Controller"/>
<constant name="struts.convention.action.mapAllMatches"
value="true"/>
<constant name="struts.convention.default.parent.package"
value="receipto"/>
<constant name="struts.convention.package.locators"
value="controllers,actions"/>

<package name="receipto" extends="json-default">
    <interceptors>
        <interceptor name="auth"
class="com.company.blah.interceptors.AuthInterceptor"/>
        <interceptor-stack name="loggingStack">
            <interceptor-ref name="servletConfig"/>
            <interceptor-ref name="json"/>
            <interceptor-ref name="auth"/>
            <interceptor-ref name="defaultStack"/>
        </interceptor-stack>
    </interceptors>
    <default-interceptor-ref name="loggingStack"/>

    <global-results>
        <result name="error">/service/error.json</result>
    </global-results>

    <action name="ping"
class="com.company.blah.actions.service.PingAction"/>
    <action name="error"
class="com.company.blah.actions.service.ErrorAction"/>
</package>

If I supply an invalid api key in the header, it simply returns me an invalid receipt object like this:

{
    "receiptId": null,
    "subtotal": 0,
    "total": 0,
    "createdAt": 1421119694657,
    "updatedAt": 1421119694657
}

Logs also don't say anything of the essence.

Is there a better way?

Thank you




HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .