React Native - 值“3130049174”不适合 32 位有符号整数
React Native - Value '3130049174' doesn't fit into a 32 bit signed int
我试图通过传递 URL 中的一些值来调用 API - 这在 iOS 上工作正常但在 Android 上中断。
例如api/v1/betslip/6/113672/669203/149/3130049174?product_id=5
值3130049174
导致错误:
中的第54行触发的
所以它在 integer != javaint
失败了
完整代码如下:
getBetslipApi(settingsObj, 113672, 669203, 149, 3130049174)
export function getBetslipApi(settings, eventID, marketID, rsID, partnerID) {
//THE RSID IS THE VALUE CAUSING THE ERROR - 3130049174
const url = settings.api+"v1/betslip/"+settings.sport_id+"/"+eventID+"/"+marketID+"/"+partnerID+"/"+rsID+"?product_id="+settings.product_id;
return (dispatch) => {
dispatch(getBetslip());
axios.get(url, {
headers: {'Cache-Control': 'max-age='+settings.api_cache_time},
timeout: settings.api_timeout
})
//THIS DOES NOT TRIGGER
.then((data) => {
console.log(data)
if(data.success) {
const url = data.data.betslip
Linking.canOpenURL(url).then(supported => {
if (!supported) {
console.log('Error opening external URL: ' + url);
return Linking.openURL(url);
} else {
return Linking.openURL(url);
}
}).catch(err => console.error('An error occurred', err));
dispatch(getBetslipSuccess(data.data))
}else {
apiError(data, url);
dispatch(getBetslipFailure(data));
}
})
.catch(function (error) {
console.log(error)
apiError(error, url);
dispatch(getBetslipFailure(error));
});
}
}
3,130,049,174 对于带符号的 32 位整数来说太大了。 maximum value for a signed integer in Java 是 2,147,483,647 (2^31 -1)。
int
是一个 32 位有符号整数,这意味着它的最小值为 2^-31,最大值为 2^31-1
3130049174 是一个超出范围的数字,这就是它导致此问题的原因。您可以使用 double
或 Integer
包装器 class 来避免此问题。
我试图通过传递 URL 中的一些值来调用 API - 这在 iOS 上工作正常但在 Android 上中断。
例如api/v1/betslip/6/113672/669203/149/3130049174?product_id=5
值3130049174
导致错误:
所以它在 integer != javaint
完整代码如下:
getBetslipApi(settingsObj, 113672, 669203, 149, 3130049174)
export function getBetslipApi(settings, eventID, marketID, rsID, partnerID) {
//THE RSID IS THE VALUE CAUSING THE ERROR - 3130049174
const url = settings.api+"v1/betslip/"+settings.sport_id+"/"+eventID+"/"+marketID+"/"+partnerID+"/"+rsID+"?product_id="+settings.product_id;
return (dispatch) => {
dispatch(getBetslip());
axios.get(url, {
headers: {'Cache-Control': 'max-age='+settings.api_cache_time},
timeout: settings.api_timeout
})
//THIS DOES NOT TRIGGER
.then((data) => {
console.log(data)
if(data.success) {
const url = data.data.betslip
Linking.canOpenURL(url).then(supported => {
if (!supported) {
console.log('Error opening external URL: ' + url);
return Linking.openURL(url);
} else {
return Linking.openURL(url);
}
}).catch(err => console.error('An error occurred', err));
dispatch(getBetslipSuccess(data.data))
}else {
apiError(data, url);
dispatch(getBetslipFailure(data));
}
})
.catch(function (error) {
console.log(error)
apiError(error, url);
dispatch(getBetslipFailure(error));
});
}
}
3,130,049,174 对于带符号的 32 位整数来说太大了。 maximum value for a signed integer in Java 是 2,147,483,647 (2^31 -1)。
int
是一个 32 位有符号整数,这意味着它的最小值为 2^-31,最大值为 2^31-1
3130049174 是一个超出范围的数字,这就是它导致此问题的原因。您可以使用 double
或 Integer
包装器 class 来避免此问题。