[英]JsonReaderException , when invoke AWS lambda function from Android
Hi I'm trying to invoke lambda function from mobile back end . 嗨,我正在尝试从移动后端调用lambda函数。
I have generated Lambda function by using .Net Core 我已经通过使用.Net Core生成了Lambda函数
public string FunctionHandler(string text, ILambdaContext
{
return qrcode;
}
This invoke fine without any errors in .net core and AWS console. 这样可以很好地调用.NET Core和AWS控制台,而不会出现任何错误。
But when i try to invoke it from Android Studio i got following error . 但是,当我尝试从Android Studio调用它时,出现以下错误。
{
"errorType": "JsonReaderException",
"errorMessage": "Unexpected character encountered while parsing value: {. Path '', line 1, position 1.",
"stackTrace": [
"at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)",
"at Newtonsoft.Json.JsonTextReader.ReadAsString()",
"at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)",
"at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)",
"at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)",
"at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)",
"at lambda_method(Closure , Stream , Stream , ContextInfo )"
]
}
Java Code , Java代码
CognitoCachingCredentialsProvider cognitoProvider = new CognitoCachingCredentialsProvider(MainActivity.this, "xxxxx", xxxxx);
LambdaInvokerFactory factory = new LambdaInvokerFactory(MainActivity.this,
xxxxx, cognitoProvider);
final MyInterface myInterface = factory.build(MyInterface.class);
RequestClass request = new RequestClass("Hello World");
new AsyncTask<RequestClass, Void, ResponseClass>() {@Override protected ResponseClass doInBackground(RequestClass... params)
{
try {
return myInterface.TestApp(params[0]);
} catch (LambdaFunctionException lfe) {
Log.e("Tag", "Failed to invoke echo", lfe);
return null;
}
catch(Exception e){
Log.e("Tag", "Failed to invoke echo", e);
return null;
}
}
Interface : 介面
import com.amazonaws.mobileconnectors.lambdainvoker.LambdaFunction;
public interface MyInterface {
@LambdaFunction(functionName="TestApp")
ResponseClass TestApp(RequestClass request);
}
As your lambda function accept a string parameter and return a string, your interface for the function should be like: 当您的lambda函数接受一个字符串参数并返回一个字符串时,该函数的接口应类似于:
public interface MyInterface { 公共接口MyInterface {
@LambdaFunction(functionName="TestApp")
String TestApp(String request);
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.