我正在解析一个包含字符串数组的JSON对象:
var ii interface{}
json := "{\"aString\": [\"aaa_111\", \"bbb_222\"], \"whatever\":\"ccc\"}"
err := json.Unmarshal([]byte(json), &ii)
if err != nil {
log.Fatal(err)
}
data := ii.(map[string]interface{})
fmt.Println(data["aString"]) // outputs: ["aaa_111" "bbb_222"]
Run Code Online (Sandbox Code Playgroud)
我试图转换data["aString"]为[]字符串以便能够循环它,但它失败了:
test := []string(data["aString"]).([]string)
fmt.Println(test) // panic -> interface conversion:
// interface is string, not []string
Run Code Online (Sandbox Code Playgroud)
我怎么转换data["aString"]?
我没有正确表达自己.如果我打印data,我有这样的地图:
map[aString:["BBB-222","AAA-111"] whatever:ccc]
我想循环遍历aString(以操纵每个数组条目).但我找不到如何,因为aString是type interface {}:
for i, v := range aString { // <-- fails
// ...
fmt.Println(i, v)
}
Run Code Online (Sandbox Code Playgroud)
这就是我想转换aString的原因.我不想将看起来像数组的字符串转换为数组.
我无法将使用redux的react-native应用程序通过remote-redux-devtools连接到redux-devtools-extension。
我正在使用通过MacOSX Sierra上的USB连接的android设备。
// configureStore.js
import { createStore, applyMiddleware } from "redux";
import { composeWithDevTools } from 'remote-redux-devtools';
import thunk from "redux-thunk";
import rootReducer from "./reducers";
const composeEnhancers = composeWithDevTools({ realtime: true });
export default function configureStore(initialState) {
const store = createStore(
rootReducer,
initialState,
composeEnhancers(
applyMiddleware(thunk),
)
);
if (module.hot) {
// Enable hot module replacement for reducers
module.hot.accept(() => {
const nextRootReducer = require('./reducers/index').default;
store.replaceReducer(nextRootReducer);
});
}
return store;
};
Run Code Online (Sandbox Code Playgroud)
Redux已正确配置到应用中,只需执行简单的按钮操作即可更新Redux状态。
但是它找不到任何商店。
我想念什么?