我能够使用JSON.parse解析单个对象。
var testing = '{"appid": "730", "contextid": "2", "amount": "1", "assetid": "2883267603"}';
var itemsObject = JSON.parse(testing);
但是当我尝试用多个对象解析变量时:
var testing = '{"appid": "730", "contextid": "2", "amount": "1", "assetid": "2883267603"}, {"appid": "730", "contextid": "2", "amount": "1", "assetid": "3084880561"}';
var itemsObject = JSON.parse(testing);
我收到以下错误:
SyntaxError: Unexpected token ,
答案 0 :(得分:4)
你需要制作一个对象数组
data, target = load_data(minibatch_index) # load_data returns typical numpy.ndarrays for a given minibatch
data_shared = theano.shared(np.asarray(data, dtype=theano.config.floatX), borrow=True)
target_shared = T.cast(theano.shared(np.asarray(target, dtype=theano.config.floatX), borrow=True), 'int32')
cost_ij = train_model(data_shared ,target_shared )
答案 1 :(得分:2)
因为testing
现在是一个(如你所说 - 多个)对象的数组,你应该在它们周围加上方括号来表示:
var testing = '[{"appid": "730", "contextid": "2", "amount": "1", "assetid": "2883267603"}, {"appid": "730", "contextid": "2", "amount": "1", "assetid": "3084880561"}]';
答案 2 :(得分:-1)
试试这个: var testing =' [{" appid":" 730"," contextid":" 2","金额& #34;:" 1"," assetid":" 2883267603"},{" appid":" 730" ," contextid":" 2","金额":" 1"," assetid":" 3084880561"}]&#39 ;; var itemsObject = JSON.parse(testing);