有人可以给我一步一步的指南,将Gson库添加到Android项目中吗?
我尝试了JSON内置库,但现在看起来有点单调乏味.我看到了几个基于Gson的例子,这看起来很简单.
我是本机反应的新手,我正在尝试向我的 API 发送一些数据,基本上是一个 POST 请求,添加了一个按钮并尝试使用它来调用获取请求,但我不确定我做错了什么这个 ??它在日志中显示“请将方法附加到此组件”,如果我在这方面做错了什么,请告诉我?
这是我的按钮
<Button
style={{height: 60,width:150}}
onClick={ () => this.submitNewCustomer()}
title="SUBMIT"
backgroundColor='#C0C0C0'
color="black"
/>
Run Code Online (Sandbox Code Playgroud)
这是我的方法
submitNewCustomer(){
fetch('http://endpoint.net/api/customerdetail', {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json', // <-- Specifying the Content-Type
}),
body: JSON.stringify({
CustomerId: '1ef87a90-a941-4ebb-b101-66f74ac07778',
CustomerName: this.state.customername,
UserId:'user2',
VehicleCompanyName:this.state.vehiclecompanyname,
VehicleModelType:this.state.vehiclemodeltype,
VehicleNumber:this.state.vehiclenumber,
CustomerImage:'',
Location:'',
CustomerImageType:'png'
}), // <-- Post parameters
})
.then((response) => response.text())
.then((responseText) => {
alert(responseText);
})
.catch((error) => {
console.error(error);
});
}
Run Code Online (Sandbox Code Playgroud)
任何输入都会非常有帮助
我已经定义了一个像这样的自定义类型的字典,
public readonly Dictionary<PricingSection, View> _viewMappings = new Dictionary<PricingSection, View>();
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试做
_viewMappings.GetValueOrDefault(section);
Run Code Online (Sandbox Code Playgroud)
部分是类型 PricingSection
我收到一个错误说
严重性代码描述项目文件行抑制状态错误CS1061"字典"不包含"GetValueOrDefault"的定义,并且没有可访问的扩展方法"GetValueOrDefault"接受类型为"Dictionary"的第一个参数(您是否缺少using指令或装配参考?)
我错过了什么?
我已经创建了一个 Azure 通知中心命名空间,我尝试通过输入 API 密钥来配置它的 Google FCM 部分,但是当我这样做时,它给了我这个错误
更新通知中心时出错 {"error":{"code":"BadRequest","message":"Firebase 凭据无效。"}}
我从 google-services.json 文件中添加的密钥
但是,当我从 FCM 控制台发送通知时,我可以发送并接收通知。
任何意见将不胜感激
xamarin.android azure-notificationhub xamarin.forms firebase-cloud-messaging