Read response as JSON.
@param app the app object
@param content the object that was read
@return status code 200 or 404
498658
public static Response getReadResponse(App app, ParaObject content) {
		try (final Metrics.Context context = Metrics.time(app == null ? null : app.getAppid(),
				RestUtils.class, "crud", "read")) {
			// app can't modify other apps except itself
			if (app != null && content != null &&
					checkImplicitAppPermissions(app, content) && checkIfUserCanModifyObject(app, content)) {
				return Response.ok(content).build();
			}
			return getStatusResponse(Response.Status.NOT_FOUND);
		}
	}
1014095
function renderJSON( request, reply, err, result ){
	if(err){
		if(err.code === 404){
			reply(new hapi.error.notFound(err.message));
		}else{
			reply(new hapi.error.badRequest(err.message));
		}
	}else{
		reply(result).type('application/json; charset=utf-8');
	}
}
179364
protected void response( int code, String data )
    {    
        /*
         * send the json content type and the charset 
        */
        response.setContentType("application/json;charset="+config.getCharset());
        
        JSONWriter json = JSONWriter.create()
                    .put("code", code)
                        .put("data", data);
        
        /*IStringBuffer sb = new IStringBuffer();
        sb.append("{\n");
        sb.append("\"status\": ").append(status).append(",\n");
        sb.append("\"errcode\": ").append(errcode).append(",\n");
        sb.append("\"data\": ");
        if ( data.charAt(0) == '{' || data.charAt(0) == '[' ) {
            sb.append(data).append('\n');
        } else {
            sb.append('"').append(data).append("\"\n");
        }
        sb.append("}\n");*/
        
        output.println(json.toString());
        output.flush();
        
        //let the gc do its work
        json = null;
    }
1106961
public String parseErrorCode(HttpResponse response, JsonContent jsonContent) {
        String errorCodeFromHeader = parseErrorCodeFromHeader(response.getHeaders());
        if (errorCodeFromHeader != null) {
            return errorCodeFromHeader;
        } else if (jsonContent != null) {
            return parseErrorCodeFromContents(jsonContent.getJsonNode());
        } else {
            return null;
        }
    }
1171703
public byte[] postBytes(byte[] content) throws IOException {

        if (!connection.isOpen())
            connection.open();

        connection.prepare("POST");

        OutputStream os = connection.getOutputStream();
        os.write(content);

        response = connection.readInput();
        os.close();
        return getResponseBytes();
    }
847627
function(app) {

  var filepath = path.join(app.dir, APP_CONFIG_FILENAME);

  // Read contents of file.
  return Promise.fromNode(function(cb) {
    fs.readFile(filepath, {encoding: 'utf8'}, cb);
  })
  // Handle no entry error.
  .catch(function(err) {
    if (err.code === 'ENOENT') {
      cacheBadApp(app);
    } else {
      throw new VError(err, 'Failed to load config: %s', filepath);
    }
  })
  // Return appName.
  .then(function(data) {
    var json = util.yaml.dataToJson(data);
    if (!json) {
      return null;
    }
    else if (!json.name) {
      log.debug(format('Does NOT contain %s property!', filepath));
      return null;
    }
    else if (json.name === app.name) {
      cacheApp(app);
      return app;
    }
    else if (json.name !== app.name) {
      cacheBadApp(app);
      return null;
    }
    else {
      return null;
    }
  });

}
1166023
private Entity<String> serialize(Object obj, String contentType) throws ClientErrorException {
        if (contentType.startsWith("application/json")) {
            try {
                return Entity.json(jsonMarshaller.serialize(obj));
            } catch (JsonMarshallingException e) {
                String msg = "Failed marshalling object to JSON data for sending to server: "+e.getMessage();
//                throw new ClientErrorException(Response.Status.BAD_REQUEST, e);
                throw new BadRequestServiceException(
                        new RestFaultInfo("BadRequest", Blame.CLIENT,
                                msg, ""+ ErrorCodes.Client.MARSHALLING_FAILED.getCode(),
                                null,
                                Retry.no(), Retry.no(),
                                Response.Status.BAD_REQUEST.getStatusCode(),
                                Response.Status.BAD_REQUEST.getReasonPhrase()
                        ), e
                );
            }
        } else {
            String msg = "Content type \"" + contentType + "\" is not supported.";
//            throw new NotSupportedException(msg);
            throw new BadRequestServiceException(
                    new RestFaultInfo("BadRequest", Blame.CLIENT,
                            msg, ""+ ErrorCodes.Client.UNSUPPORTED_TECHNOLOGY.getCode(),
                            null,
                            Retry.no(), Retry.no(),
                            Response.Status.BAD_REQUEST.getStatusCode(),
                            Response.Status.BAD_REQUEST.getReasonPhrase()
                    )
            );
        }
    }
1151776
private static JSONObject parseRequestJSONObject(final HttpServletRequest request, final HttpServletResponse response) {
        response.setContentType("application/json");

        try {
            BufferedReader reader;
            try {
                reader = request.getReader();
            } catch (final IllegalStateException illegalStateException) {
                reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
            }

            String tmp = IOUtils.toString(reader);
            if (StringUtils.isBlank(tmp)) {
                tmp = "{}";
            } else {
                if (StringUtils.startsWithIgnoreCase(tmp, "%7B%22" /* {" */)) {
                    tmp = URLs.decode(tmp);
                }
            }

            return new JSONObject(tmp);
        } catch (final Exception e) {
            LOGGER.log(Level.ERROR, "Parses request JSON object failed [" + e.getMessage() + "], returns an empty json object");

            return new JSONObject();
        }
    }
276980
@SuppressWarnings("unchecked")
    public <T> T readAsObject(byte[] content, Class<T> type) {
        try {
            if (content == null || content.length == 0 || type == null) {
                log.debug("content为{}，type为：{}", content, type);
                return null;
            } else if (type.equals(String.class)) {
                return (T) new String(content);
            }
            return MAPPER.readValue(content, type);
        } catch (Exception e) {
            log.error("json解析失败，失败原因：", e);
            return null;
        }
    }
37810
public GetAppResponse queryApp(String app) {
        GetAppRequest request = new GetAppRequest();
        request.setApp(app);
        return queryApp(request);
    }
584861
def get_json_request(self):
        
        content_type = request.headers.get('Content-Type', 'text/plain')
        if content_type not in ('application/json', 'text/json'):
            self.log.error('get_json_request() called in a request that does not have a json content-type: %s. Refusing to parse the request data', content_type)
            return {}

        try:
            data = json.loads(request.data)
        except ValueError:
            self.log.exception(
                "Trying to parse json body in the %s to %s",
                request.method, request.url,
            )
            data = {}

        return data
1036369
def _as_json(self, response):
        
        # Assume ClientResponse has "body", and otherwise it's a requests.Response
        content = response.text() if hasattr(response, "body") else response.text
        try:
            return json.loads(content)
        except ValueError:
            raise DeserializationError(
                "Error occurred in deserializing the response body.")
557855
protected Object readResponse(Type returnType, JsonNode jsonObject) throws Throwable {
		return readResponse(returnType, jsonObject, null);
	}
433173
@SuppressWarnings({"unchecked"})
    public <T> T read(String json, Configuration configuration) {
        notEmpty(json, "json can not be null or empty");
        notNull(configuration, "jsonProvider can not be null");

        return read(configuration.jsonProvider().parse(json), configuration);
    }
832439
protected function getResponseJson($content)
    {
        $this->response = new Response\Json\Api();
        $this->response->setHttpCode(200);
        $this->response->setContent($content);

        return $this->response;
    }
549863
private Object readJSON() throws JSONException {
        switch (read(3)) {
        case zipObject:
            return readObject();
        case zipArrayString:
            return readArray(true);
        case zipArrayValue:
            return readArray(false);
        case zipEmptyObject:
            return new JSONObject();
        case zipEmptyArray:
            return new JSONArray();
        case zipTrue:
            return Boolean.TRUE;
        case zipFalse:
            return Boolean.FALSE;
        default:
            return JSONObject.NULL;
        }
    }
791309
private IJsonInput cleanAndParseJsonString(final App app, final String input) throws FrameworkException {

		final Gson gson      = getGson();
		IJsonInput jsonInput = null;

		// isolate input parsing (will include read and write operations)
		try (final Tx tx = app.tx()) {

			jsonInput   = gson.fromJson(input, IJsonInput.class);
			tx.success();

		} catch (JsonSyntaxException jsx) {
			logger.warn("", jsx);
			throw new FrameworkException(400, jsx.getMessage());
		}

		if (jsonInput == null) {

			if (StringUtils.isBlank(input)) {

				try (final Tx tx = app.tx()) {

					jsonInput   = gson.fromJson("{}", IJsonInput.class);
					tx.success();
				}

			} else {

				jsonInput = new JsonSingleInput();
			}
		}

		return jsonInput;

	}