私のReactNative-Appを自分のデバイスでテストすると、奇妙な動作が発生しました。私が何をやっているのかを教えてくれるかもしれません。Reactネイティブでwifiの有無に応じて異なる結果を取得します
私はREST-APIを使って投稿のリストを返しています。私は無線LAN とモバイルインターネット上でこのオブジェクトを取得するために期待される
{
"status": 200,
"data": [
{
"id": "6bb373c6dbe8c4782121068223a1d5bf710a14a62943443bdc5c017ce873935a",
"description": "",
"upvotes": 0,
"downvotes": 0,
"creationTime": "2017-08-16T04:44:03Z"
},
{
"id": "5ae791aa33512dc179f075649f68731f269c366a37807f7da9eeeabafcda8c7d",
"description": "",
"upvotes": 0,
"downvotes": 0,
"creationTime": "2017-08-16T04:42:27Z"
},
],
"version": "0.0.1",
"servertime": "2017-08-16T07:02:32.250978864+02:00"
}
:ここでは郵便配達して要求されたいくつかの出力が(それは、後に上のアプリで同じURLです)。ここで
は私のアプリ内で私のAPIを要求するためcodesnipped:
exports.getPosts = function() {
return fetch(HTTP.baseurl + "/image", {
method: "GET"
}).then(res => res.json()).then((res)=>{
//this is the line you will see the output from
console.log(JSON.stringify(res, null, 2));
return res
});
}
Wi-Fi付きのAPIを要求した場合、私は郵便配達と同じオブジェクトを取得します。 しかし、モバイルインターネットで要求された場合、私は、次のオブジェクトを取得:
macOS: 10.12.6
XCode: 8.3.3
iOS: 10.3.3 (iPhone 6)
node: 8.4.0
react: 16.0.0-alpha.12
react-native: 0.45.1
EDIT:のみ、以下の行を挿入する
私も新鮮でそれを再現
が反応するネイティブアプリ{
"status": 200,
"data": {
"id": "5ae791aa33512dc179f075649f68731f269c366a37807f7da9eeeabafcda8c7d",
"description": "",
"upvotes": 0,
"downvotes": 0,
"creationTime": "2017-08-16T06:42:27.37228137+02:00"
},
"version": "0.0.1",
"servertime": "2017-08-16T06:42:27.4874009+02:00"
}
でテストをコード:
//first send an image to the API
fetch("http://services.impressions-app.com/test/image", {
method: "POST",
body: JSON.stringify({"blob": blob, "description": ""})
}).then(res => res.json()).then(res => {
//then request all the images including the new one
return fetch("http://services.impressions-app.com/test/image", {
method: "GET"
})
}).then(res => res.json()).then(res => {
//should log an array of imageobjects (see postman response above)
console.log("LOADED", res);
}).catch(e => {
console.error(e)
});
私はd ATA配列の代わりにオブジェクトとして:
{
"status": 200,
"data": {
"id": "06c50436c2b2b671a64ce3b57b6cac76b648a83ed621305a0f6a55f8186957ba",
"description": "",
"upvotes": 0,
"downvotes": 0,
"creationTime": "2017-08-17T08:00:24.198626835+02:00"
},
"version": "0.0.1",
"servertime": "2017-08-17T08:00:26.031231455+02:00"
}
でテスト:
macOS: 10.12.6
XCode: 8.3.3
iOS: 10.3.3 (iPhone 6)
node: 8.4.0
react: 16.0.0-alpha.12
react-native: 0.45.1
EDIT#2:
私は、ログファイルを見て、私は無線LANを介して要求されたときにのみ、この要求をログに記録しました。他の要求は期待通りに記録されました。
おそらくキャッシュの問題ですか?
誰もあなたと同じような問題がありますか?これは、キャッシュの問題である
:
ショートバージョン:
は非常に
2つの応答が最初に応答して、同じ構造ではないが 'data'プロパティが配列であるが、第二にレスポンス 'data'はオブジェクトです。あなたは彼らが同じソースから来ていると確信していますか? –
APIはわかりませんが、結果が1つだけの場合はバックエンドの開発者がオブジェクトを返すようにプログラムをプログラミングし、そうでない場合は配列を返す可能性があります。 – eden
@VahidBoreiriええ、私は何も変わらないので、彼らは間違いなく同じソースから来ている。 –