对于想了解SwiftOpenWeatherMapAPI类型“任何”错误的值的读者,本文将是一篇不可错过的文章,并且为您提供关于axios没有从openweathermapapi、Callapi和ope
对于想了解Swift OpenWeatherMap API类型“任何”错误的值的读者,本文将是一篇不可错过的文章,并且为您提供关于axios 没有从 openweathermap api、Callapi 和 openweathermap、Flutter 按日期从 openweathermap 创建数据列表、iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts
- Swift OpenWeatherMap API类型“任何”错误的值
- axios 没有从 openweathermap api
- Callapi 和 openweathermap
- Flutter 按日期从 openweathermap 创建数据列表
- iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts
Swift OpenWeatherMap API类型“任何”错误的值
如何解决Swift OpenWeatherMap API类型“任何”错误的值
嘿,我的快速代码给出了错误
“任何”类型的值没有下标
在此行
if let weatherArray = jsonObj.value(forKey: "weather") as? NSArray {
print("Type \\(weatherArray[0]["main"])")
}
我不知道如何解决它,我试图在网上搜索,但是我并没有找到解决方法
其余代码
let session = URLSession.shared
let weatherURL = url!
let dataTask = session.dataTask(with: weatherURL) {
(data: Data?,response: URLResponse?,error: Error?) in
if let error = error {
print("Error:\\n\\(error)")
}
else {
if let data = data {
let dataString = String(data: data,encoding: String.Encoding.utf8)
print("All the weather data:\\n\\(dataString!)")
if let jsonObj = try? JSONSerialization.jsonObject(with: data,options: .allowFragments) as? NSDictionary {
if let mainDictionary = jsonObj.value(forKey: "main") as? NSDictionary {
if let temperature = mainDictionary.value(forKey: "feels_like") {
dispatchQueue.main.async {
print("Feels like: \\(temperature)°C")
}
}
}
if let weatherArray = jsonObj.value(forKey: "weather") as? NSArray {
print("Type \\(weatherArray[0]["main"])")
}
解决方法
if let weatherArray = jsonObj.value(forKey: "weather") as? NSArray {
print("Type \\(weatherArray[0]["main"])")
}
您必须再次将项目投射到NSDictionary
if let weatherArray = jsonObj.value(forKey: "weather") as? NSArray,let inner = weatherArray[0] as? NSDictionary {
print("Type \\(inner["main"])")
}
,
您的weatherArray
是未广播值的数组,类似于[Any]
。当您尝试评估weatherArray[0]["main"]
时,您引用的是类型Any
的第一个元素,并尝试使用下标来获取内容,但是Any
并没有实现一个元素,因此会出现错误。
axios 没有从 openweathermap api
如何解决axios 没有从 openweathermap api
我正在尝试从 openweathermap api 获取数据。我很容易使用邮递员获得它,但我尝试使用带有 axios 请求的 nodejs 并且它以 400 状态代码响应。 我为它编写了以下代码-
try {
let a = ''london''
const data = await axios.get(
`api.openweathermap.org/data/2.5/weather?q=${a}&appid=${process.env.WEATHER_API_KEY}`
)
console.log(''the data is'',data)
if (data) {
console.log(''the data is'',data)
res.status(201).json(data)
}
} catch (error) {
console.log(''error'',error.message)
res.status(403)
res.json(error)
}
解决方法
您需要在网址中添加 http://
或 https://
。没有它们,URL 的格式不正确,axios 认为它是一个相对 URL(例如 /local/api
),但是因为您尝试在节点上执行它,它没有像在浏览器(站点起源)。
Callapi 和 openweathermap
如何解决Callapi 和 openweathermap
当我获得温度值时,我认为格式有问题。当我调用这个参数时,我总是用“d0” f.e. 得到它。 “-0,39d0”。我该如何解决?我的代码:
<category>
<pattern>PADANIE</pattern>
<template>
<think>
<set name="weather_t">
<callapi>
<url>http://api.openweathermap.org/data/2.5/weather</url>
<method>GET</method>
<query name="appid"><secret name="openweathermap_secret_appid"/></query>
<query name="q">zyrardow</query>
<query name="units">metric</query>
<query name="lang">pl</query>
<filter type="jsonpath">$.main.temp</filter>
</callapi>
</set>
</think>
<get name="weather_t"/>.
</template>
</category>
如果我使用 jsonpath 而不是 filter 结果是一样的。
<category>
<pattern>PADANIE</pattern>
<template>
<think>
<set var="weather_t">
<callapi>
<url>http://api.openweathermap.org/data/2.5/weather</url>
<method>GET</method>
<query name="appid"><secret name="openweathermap_secret_appid"/></query>
<query name="q">zyrardow</query>
<query name="units">metric</query>
<query name="lang">pl</query>
</callapi>
</set>
</think>
<jsonpath><path>$.main.temp</path><get var="weather_t"/></jsonpath>
</template>
</category>
bot answer example
Flutter 按日期从 openweathermap 创建数据列表
如何解决Flutter 按日期从 openweathermap 创建数据列表
我以 json 的形式从 openweathermap 中每隔 3 小时获取 5 天的天气数据。现在我正在制作一个数组,当我只选择我需要的数据时,但是如何按日期将它组合成一个数组或对象。也就是属于一天的所有数据?
static List<Weather> fromForecastJson(Map<String,dynamic> json) {
final weathers = List<Weather>();
for (final item in json[''list'']) {
weathers.add(Weather(
time: item[''dt''],temperature: intTodouble(
item[''main''][''temp''],),description: item[''weather''][0][''description''],iconCode: item[''weather''][0][''icon'']
));
}
return weathers;
}
iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts
如何解决iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>
我不断收到来自随机用户的随机崩溃报告。不幸的是,我无法定期重现这一点。用户说崩溃是在 discussionViewController
中随机发生的。所有崩溃报告都有类似的内容:
0 libswiftCore.dylib 0x00000001a53face4 swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::incrementSlow(swift::RefCountBitsT<(swift::RefCountInlinedness)1>,unsigned int) + 60 (atomic:1003)
1 libswiftCore.dylib 0x00000001a53c59e0 swift_retain + 124 (RefCount.h:813)
2 libswiftCore.dylib 0x00000001a5401d60 swift_bridgeObjectRetain + 56 (SwiftObject.mm:585)
3 APPNAME 0x0000000102b59734 closure #1 in discussionViewController.fetchPostData() + 7916
这是完整的崩溃日志和崩溃的线程:
Hardware Model: iphone11,6
Process: APPNAME [11770]
Path: /private/var/containers/Bundle/Application/.../APPNAME.app/APPNAME
Identifier: ----
Version: 62 (62)
AppStoretools: 12E262
AppVariant: 1:iphone11,6:13
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Coalition: ---- [1824]
Date/Time: 2021-06-17 12:07:01.4346 +1000
Launch Time: 2021-06-17 12:06:56.4993 +1000
OS Version: iPhone OS 14.6 (18F72)
Release Type: User
Baseband Version: 3.04.01
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x8000000000000010 -> 0x0000000000000010 (possible pointer authentication failure)
VM Region Info: 0x10 is not in any region. Bytes before following region: 4339515376
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
__TEXT 102a7c000-102a94000 [ 96K] r-x/r-x SM=COW ...APPNAME.app/APPNAME
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL,Code 0xb
Terminating Process: exc handler [11770]
Triggered by Thread: 3
Thread 3 name:
Thread 3 Crashed:
0 libswiftCore.dylib 0x00000001a53face4 swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::incrementSlow(swift::RefCountBitsT<(swift::RefCountInlinedness)1>,unsigned int) + 60 (atomic:1003)
1 libswiftCore.dylib 0x00000001a53c59e0 swift_retain + 124 (RefCount.h:813)
2 libswiftCore.dylib 0x00000001a5401d60 swift_bridgeObjectRetain + 56 (SwiftObject.mm:585)
3 APPNAME 0x0000000102b59734 closure #1 in discussionViewController.fetchPostData() + 7916
4 APPNAME 0x0000000102ad09d4 thunk for @escaping @callee_guaranteed (@guaranteed Data?,@guaranteed NSURLResponse?,@guaranteed Error?) -> () + 132 (<compiler-generated>:0)
5 CFNetwork 0x00000001a1b0a3dc __40-[__NSURLSessionLocal taskForClassInfo:]_block_invoke + 540 (LocalSession.mm:687)
6 CFNetwork 0x00000001a1b1c768 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 244 (LocalSessionTask.mm:584)
7 libdispatch.dylib 0x00000001a10d1a84 _dispatch_call_block_and_release + 32 (init.c:1466)
8 libdispatch.dylib 0x00000001a10d381c _dispatch_client_callout + 20 (object.m:559)
9 libdispatch.dylib 0x00000001a10db004 _dispatch_lane_serial_drain + 620 (inline_internal.h:2557)
10 libdispatch.dylib 0x00000001a10dbc34 _dispatch_lane_invoke + 456 (queue.c:3862)
11 libdispatch.dylib 0x00000001a10e64bc _dispatch_workloop_worker_thread + 764 (queue.c:6589)
12 libsystem_pthread.dylib 0x00000001ed04a7a4 0x1ed047000 + 14244
13 libsystem_pthread.dylib 0x00000001ed05174c 0x1ed047000 + 42828
我已验证 discussionViewController.fetchPostData()
不会强制解开任何可选选项,没有 try!
并且在任何地方都使用 [weak self]
和 self?
。该函数非常大,所以我很难缩小崩溃发生的范围。
今天关于Swift OpenWeatherMap API类型“任何”错误的值的讲解已经结束,谢谢您的阅读,如果想了解更多关于axios 没有从 openweathermap api、Callapi 和 openweathermap、Flutter 按日期从 openweathermap 创建数据列表、iOS Swift 应用程序随机 EXC_BAD_ACCESS 崩溃:swift_bridgeObjectRetain swift_retain swift::RefCounts
本文标签: