dlang语言以下代码如果14行去掉就可以运行否则运行的时候会抛出异常import stdjson;2import stdstdio;34void main56 string jsonString = name John age 30 city New York;7 JSONValue json = parseJSONjsonString;8 string name = js
在第13行,将一个数组赋值给了JSONValue类型的变量json2,但是JSONValue类型的变量不支持通过下标的方式赋值。因此在第14行会抛出异常。
要纠正这个问题,可以将json2改为JSON array类型,例如:
JSONValue[] json2 = ["apple", "banana", "orange"]; json2 ~= JSONValue(88);
这里使用了数组的追加操作符~,将新的JSONValue类型的元素添加到数组中。
原文地址: https://www.cveoy.top/t/topic/fo9U 著作权归作者所有。请勿转载和采集!