我正在研究离子4项目.我的项目是使用输入搜索从url获取数据json.我希望在用户点击任何项目时向其显示另一页以获取更多详细信息时传递数据.我尝试使用此代码,但我得到未定义的值!
此代码正在执行搜索操作
export class FlightsearchPage {
public search = ''
public flight : any
filterItems:any;
callsign : any;
constructor(private http: HTTP, public loadingController: LoadingController, private nav : NavController) {
this.addThemFunction
}
keyPressed(event: any) { /
console.log(event.target.value);
this.addThemFunction(event.target.value);
}
async addThemFunction(search){
this.http.get('/web/find?query='+search+'', {}, {})
.then(data => {
const parsed = JSON.parse(data.data);
this.flight = parsed.results;
this.filterItems= this.flight;
this.callsign = this.flight.detail.flight
/// here l am try to pass value callsign to page details ///
this.nav.navigateForward(`/flightserachdetails/${this.callsign}`)
}), err=>{
}
}
}
Run Code Online (Sandbox Code Playgroud)
详细搜索
<ion-content padding> …Run Code Online (Sandbox Code Playgroud) 我正在从事 ionic 4 项目。我的项目是从 url 获取数据 json 。我想检查来自 url 的图像是否损坏。如果损坏则显示另一张图像。我尝试了不同的代码,但没有人在工作。
我正在使用的代码是
<ion-row *ngFor="let item of items" justify-content-around test-center>
<ion-col >
<img src="/images/data/operators/{{item.flight.airline.code.icao}}_logo0.png" onerror="this.src='images/data/operators/{{item.flight.airline.code.iata}}_{{item.flight.airline.code.icao}}.png'">
</ion-col>
</ion-row>
Run Code Online (Sandbox Code Playgroud)
我在运行时遇到错误
ERROR Error: Uncaught (in promise): Error: Template parse errors:
Binding to event property 'onerror' is disallowed for security reasons, please use (error)=...
If 'onerror' is a directive input, make sure the directive is imported by the current module.
Run Code Online (Sandbox Code Playgroud)
取决于错误,如果我使用(error)=我得到另一个错误是
ERROR Error: Uncaught (in promise): Error: Template parse errors:
Parser Error: Got interpolation …Run Code Online (Sandbox Code Playgroud) 我正在从我的服务器获取 JSON 字符串。我的数据看起来像这样(JSON 数组)
{
"result": {
"response": {
"data": [
{
"identification": {
"id": null,
"number": {
"default": "IA224",
"alternative": null
},
"callsign": null,
"codeshare": null
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
但有时如果我输入了错误的信息,此数据可能是(JSON 对象)或为空
data : null
Run Code Online (Sandbox Code Playgroud)
我想在其对象时执行不同的操作,在其数组时执行不同的操作。我收到以下异常
Caused by: org.json.JSONException: Value null of type org.json.JSONObject$1 cannot be converted to JSONArray
Run Code Online (Sandbox Code Playgroud)
我做了这个代码,但他不工作
val jsonArray = JSONArray(response.get("data").toString())
if(jsonArray.isNull(0)){
jsonArray.getJSONObject(0).getString("data");
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试解析在我的应用程序中使用 gson 和 okhttp 的 JSON 字符串数据。l 使用回收视图来显示数据。当我运行应用程序时,我得到了致命的例外
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.iraqairoirt.iraqairports, PID: 20692
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
at com.google.gson.Gson.fromJson(Gson.java:927)
at com.google.gson.Gson.fromJson(Gson.java:892)
at com.google.gson.Gson.fromJson(Gson.java:841)
at com.google.gson.Gson.fromJson(Gson.java:813)
at com.iraqairoirt.iraqairports.NotamOrbi$fetchjson$1.onResponse(NotamOrbi.kt:55)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter
Run Code Online (Sandbox Code Playgroud)
我的主要活动
class NotamOrbi : AppCompatActivity() {
override fun …Run Code Online (Sandbox Code Playgroud) 我有以下JSON结构:
{
"daypart": [
{
"temperature": [
45,
27,
47
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试从JSON API显示上面的数组。我只想显示此数组中的第一个元素,但出现以下错误
Error: Uncaught (in promise): TypeError: Cannot read property '1' of undefined
Run Code Online (Sandbox Code Playgroud)
代码:
this.http.get("xxxxxxxx")
.subscribe(data => {
let f = data["daypart"][0]
this.duhok = f
console.log("duhok" + this.duhok["temperature"][1])
})
Run Code Online (Sandbox Code Playgroud)
HTML:
{{duhok.temperature[1]}}°
Run Code Online (Sandbox Code Playgroud)