NSnull 类型的 JSON 值无法转换为 NSString
Posted
技术标签:
【中文标题】NSnull 类型的 JSON 值无法转换为 NSString【英文标题】:JSON value of type NSnull cannot be converted to NSString 【发布时间】:2017-04-10 10:25:18 【问题描述】:我的 react-native Firebase APL 有一个奇怪的错误。
react-native run-android 工作正常,没有错误。
但是 react-native run-ios 失败,。
源代码如下。(主要和注册类在firebase上进行身份验证工作)
我认为 Firebase Class 在 ios 和 Android 上有不同的 ACT 来将 JSON 转换为文本。
任何建议表示赞赏。
商事
主要
// 在此处初始化firebase应用并根据需要将其传递给其他组件。仅在启动时初始化。
const firebaseApp = firebase.initializeApp(firebaseConfig);
var GiftedMessenger = require('react-native-gifted-messenger');
let styles =
class Pricing extends Component
constructor(props)
super(props);
this.state =
page: null
;
/* this.itemsRef = this.getRef().child('items'); */
componentWillMount()
// We must asynchronously get the auth state, if we use currentUser here, it'll be null
const unsubscribe = firebaseApp.auth().onAuthStateChanged((user) =>
// If the user is logged in take them to the accounts screen
if (user != null)
this.setState(page: Account);
console.log('(user != null)')
return;
// otherwise have them login
console.log('(user != Login)')
this.setState(page: Login);
// unsubscribe this observer
unsubscribe();
);
render()
if (this.state.page)
return (
// Take the user to whatever page we set the state to.
// We will use a transition where the new page will slide in from the right.
<Navigator
initialRoute=component: this.state.page
configureScene=() =>
return Navigator.SceneConfigs.FloatFromRight;
renderScene=(route, navigator) =>
if(route.component)
// Pass the navigator the the page so it can navigate as well.
// Pass firebaseApp so it can make calls to firebase.
return React.createElement(route.component, navigator, firebaseApp);
/>
);
else
return (
// Our default loading view while waiting to hear back from firebase
【问题讨论】:
这个错误似乎很具体。问题应该尝试做同样的事情。 CLASS firebase 调用我的 APL 如下。常量 firebaseApp = firebase.initializeApp(firebaseConfig); const unsubscribe = firebaseApp.auth().onAuthStateChanged((user) => this.props.firebaseApp.auth().createUserWithEmailAndPassword( const userData = this.props.firebaseApp.auth().currentUser; source=uri: this.state.user.photoURL /> // 注销,一旦完成,将用户返回到登录屏幕 this.props.firebaseApp.auth().signOut().then(() => 【参考方案1】:我在这个BUG中深度调试。 最后找到如下。
<Image
source=uri: 'this.state.user.photoURL' <<<single quotation was added.
style=styles.image
/>
没想到会出现这种错误。
谢谢庄司
【讨论】:
为什么ios和Android不用单引号会做不同的动作?【参考方案2】:得到了@itagaki 的帮助。在以下代码中将单引号替换为双引号后,错误已删除
const BoldText = (props) => <Text style=fontWeight: 'bold'>props.children</Text>;
【讨论】:
以上是关于NSnull 类型的 JSON 值无法转换为 NSString的主要内容,如果未能解决你的问题,请参考以下文章