gpt4 book ai didi

java - JsonReaderException ,当从 Android 调用 AWS lambda 函数时

转载 作者:太空宇宙 更新时间:2023-11-04 10:09:25 26 4
gpt4 key购买 nike

您好,我正在尝试从移动后端调用 lambda 函数。

我使用.Net Core生成了Lambda函数

      public string FunctionHandler(string text, ILambdaContext 
{
return qrcode;
}

此调用正常,在 .net core 和 AWS 控制台中没有任何错误。

但是当我尝试从 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 代码,

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;
}
}

界面:

import com.amazonaws.mobileconnectors.lambdainvoker.LambdaFunction;
public interface MyInterface {
@LambdaFunction(functionName="TestApp")
ResponseClass TestApp(RequestClass request);

}

最佳答案

由于您的 lambda 函数接受字符串参数并返回字符串,因此该函数的接口(interface)应如下所示:

公共(public)接口(interface)MyInterface{

@LambdaFunction(functionName="TestApp")
String TestApp(String request);

}

关于java - JsonReaderException ,当从 Android 调用 AWS lambda 函数时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52530262/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com