我试图找出一些代码来从JSON文件中提取配置。 当我尝试构建时,出现此错误
以下是我正在尝试使用的配置和程序代码。 我目前发现的每个例子都与下面的代码类似。 任何关于我做错了什么的建议?
I'm trying to work out a bit of code to pull in config from a JSON file. When I attempt to build, I get this error
Below is the config and program code I'm trying to work with. Every example I've found so far is similar to the below code. Any suggestion of what I'm doing incorrectly?
type ConfigVars is not an expression
-- Config File
{"beaconUrl":"http://test.com/?id=1"}
-- Program Code
package main
import (
"encoding/json"
"fmt"
"os"
)
type ConfigVars struct {
BeaconUrl string
}
func main() {
configFile, err := os.Open("config.json")
defer configFile.Close()
if err != nil {
fmt.Println("Opening config file", err.Error())
}
jsonParser := json.NewDecoder(configFile)
if err = jsonParser.Decode(&ConfigVars); err != nil {
fmt.Println("Parsing config file", err.Error())
}
}
type ConfigVars is not an expression
-- Config File
{"beaconUrl":"http://test.com/?id=1"}
-- Program Code
package main
import (
"encoding/json"
"fmt"
"os"
)
type ConfigVars struct {
BeaconUrl string
}
func main() {
configFile, err := os.Open("config.json")
defer configFile.Close()
if err != nil {
fmt.Println("Opening config file", err.Error())
}
jsonParser := json.NewDecoder(configFile)
if err = jsonParser.Decode(&ConfigVars); err != nil {
fmt.Println("Parsing config file", err.Error())
}
}
你在那里做的是试图传递一个指向
ConfigVars
类型的指针(这显然并不意味着什么)。 你想要做的是制作一个类型为ConfigVars
的变量,并传递一个指向它的指针:What you're doing there is trying to pass a pointer to the
ConfigVars
type (which obviously doesn't really mean anything). What you want to do is make a variable whose type isConfigVars
and pass a pointer to that instead:
var cfg ConfigVars
err = jsonParser.Decode(&cfg)
...
var cfg ConfigVars
err = jsonParser.Decode(&cfg)
...
相关问答
你提供的php链接之后的JSON以{和教程所说的那样,这是一个JSON对象,后跟一个名为“receptai”的数组。 如果你已经正确地学习了教程直到最后,它应该使用makeJsonArrayRequest() 您确实需要在此处粘贴代码,以便我们可以进一步提供帮助。 您可能首先要做的就是按照教程的呈现方式完成教程,如果成功获得答案,则开始进行实验和更改。 我看到你正在使用自己的JSON,而不是编写JsonArrays和JsonObjects,并看到两个按钮都可以正常工作。 Your JSON fol...
你可以使用RegExp /application\/json/ var response = {"Content-Type":"application/json;charset=UTF-8"};
console.log(response["Content-Type"].match(/application\/json/)[0]); You can use RegExp /application\/json/ var response = {"Content-Type":"application/...
你可以使用|| (或)布尔运算符。 基于您的堆栈跟踪,您的表达式应该类似于: expresion= "execution(public com.es.core.message.ResultOrError com.presentation.resource..*.*(com.es.mus.MUSIn,..) || java.util.concurrent.Future com.presentation.resource..*.*(com.es.mus.MUSIn,..)|| scala.concu...
将我的评论转化为答案 由于CMake需要在配置步骤中浏览所有CMakeLists.txt文件,答案是肯定的,您必须始终调用add_subdirectory() 。 我认为你要找的是EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG>目标属性。 Turning my comment into an answer Since CMake needs to go through all your CMakeLists.txt files during configuration ste...
那么,问题在于你如何创建Lambda 。 他们应该从T开始,而不是从Layer : var startsWith = Expression.Lambda<Func<T, bool>>(methodExpStartsWith, parameterExp);
var equals = Expression.Lambda<Func<T, bool>>(methodExpEquals, parameterExp);
然而,为了这个工作,你又缺少一个PropertyExpression 。 您的查询现在看...
转换遵循整数转换等级原则。 简而言之,当整数操作数是: 完全一样,没有转换发生。 大小相同,无符号优先。 不同大小,更小转换为更大。 如果大于无符号,则较小也转换为无符号。 该转换将操作数转换为相同的类型,这也是结果的类型。 它覆盖了C ++ 11标准的[expr]§9 。 它也与[conv]和[conv.rank]密切相关。 具体适用哪些操作员在[expr]子章节中对各个操作员的描述进行了介绍。 Conversions follow the integer conversion rank pri...
在F#中,函数的返回值是函数中最后一个表达式。 所以,让我们关注以下内容: if ex < 1 then
if ex = 0 then res (* <--- this is not an early return *)
ex <- -ex (* <--- F# evaluates this code after the *)
n <- 1 / n (* if statement *)
此外,...
在您的情况下,您遇到此错误两次: 在你正确编辑的for循环中 因为编译器不知道boo的类型(它只是NSMutableArray一个元素。 要解决这个问题,你可以写 for var boo in mutableObjects {
if var theBoo = boo as? NSMutableDictionary {
if (theBoo["name"] as! String) == "BookB" {
print (theBoo["isRead"...
count_l_in_word initial+1 (Str.string_after word 1)
被解析为 (count_l_in_word initial) + (1 ((Str.string_after word) 1))
所以你需要添加一些parens: count_l_in_word (initial + 1) (Str.string_after word 1)
count_l_in_word initial+1 (Str.string_after word 1)
is pa...
你在那里做的是试图传递一个指向ConfigVars类型的指针(这显然并不意味着什么)。 你想要做的是制作一个类型为ConfigVars的变量,并传递一个指向它的指针: var cfg ConfigVars
err = jsonParser.Decode(&cfg)
...
What you're doing there is trying to pass a pointer to the ConfigVars type (which obviously doesn't really mean a...
solr config 部分注解 <?xml version="1.0"
...
在使用jsp生成web图片时遇到这个问题,这是源代码中的一条语句,源代码可以执行,可是一将源码放入ec
...
Data-config为solr的data-import处理器配置数据来源。 依次按照如下树状结构:
...
POST提交时总是报错: {"errcode":40017,"errms
...
在编写后台登陆模块时,将许多默认的设置放在一个名为default的package 里。然后再定义其他
...
我做了一个这样的框架: spring+hibernate+spring mvc 想让spring
...
最近在开发微信平台,要使用JSON进行数据交换,之前用过JSON,但仅限于…… 在开发微信平台中,要使
...
Json.Net学习笔记(十四) JSON的部分序列化 通常当用到大的Json文档的时
...
环境:Apache solr4.8,maven3,IntellijIDEA 想在项目中使用solr 在
...
最新问答
一个变量,当被引用时应该用$引导(当声明时,它不是)。 并且,您应该将参数替换变为“file”变量: for file in california*; do mv "$file" "${file/california/c}"; done A variable, when referred should be led with a $ (when declared, it is not). And, you should make parameter substition into "file"
这有效: ul { height: auto; width:100%; } ul li { display: block; padding: 20px; } @media(min-width: 480px){ ul{ -webkit-column-count: 1; -moz-column-count: 1; column-count: 1; } } @media(min-wid
根据你的代码,我猜PRINTN是子程序(函数,过程等),它使用JSR调用。 如果是这样,你应该介意JSR的功能:它 SP减4 通过SP中的地址将返回地址(JSR之后的指令的开头)放到内存中 将子程序地址(从JSR指令)提供给PC 所以,在它之后,你知道的所有超出SP的偏移应该增加4.并且,从0(SP)中的值作为子程序中的4(SP)被访问,28(SP)将以相同的方式被替换与32(SP)等等。 RTS反过来 - 它将SP增加4。 而且,每个PUSH和POP都会改变它; 如果您在堆栈中保存2个寄存器,
连接超时没有RFC。 任何RFC或其他文档都不可能事先知道任何网络中的主要条件。 一般来说,您可以期待成功的连接非常快; 一个ECONNREFUSED ( ConnectException: connection refused )快速; 和连接超时( ConnectException: connect timeout ),只要它需要,取决于原因,两端的平台,以及介入网络的性质。 在Windows中,我认为连接超时包括三次连接尝试的总时间,超时为6s,12s和24s,总共42s; 在各种Unix
这是99%的依赖性问题。 你的一个罐子与同一个罐子的另一个版本发生冲突,可能与servlet依赖关系有关。 你能分享一下你的pom.xml吗? This is 99% a dependency issue. One of your jars is clashing with another version of the same jar and probably related to a servlet dependency. Can you share your pom.xml?
你不能。 您需要调用.getlist('category') ,但不能在模板中使用参数调用方法。 You can't. You need to call .getlist('category'), but you can't call methods with a parameter in a template.
首先,用任何支持的选项初始化fullcalendar。 接下来,使用您选择的触发器调用gotoDate方法。 在这个例子中,触发器将是一个按钮点击。 HTML Go to 2017-12-15 JS $(function(){ $('#my_calendar').fullCalendar({ // your options here... });
在下面的代码中,Counter是一个静态内部类,但它可以实例化,就好像它不是: 内部类(无论是否为static )可以实例化,就像普通类一样。 使类static只允许您访问它而无需创建封闭类的实例。 就像你在那段代码中那样: Counter counter1 = new Task.Counter(); 在这里,您将创建一个Counter实例。 但由于Counter是一个嵌套类(我们称之为static inner类),我们必须像这样访问它。 Task.Counter是Counter类的完全
这是一个例子: HTML Add Record Form First Name:
检查javascript对象时,未结束的对象引用没有任何问题。 它们基本上在对象引用中形成循环图。 但是,这意味着您可以获得循环图的优点和不足。 遍历/遍历图形时,您需要通过跟踪已经访问过的对象并且不要多次访问它们来小心无限循环。 (即通过跟踪visited地图) There is nothing wrong with un-ending object references when you inspect an javascript object. They essentially form