I use JSONObjectWithData to parse a JSON, and was using the following code to retrieve information:
fotos[0]!["foto"]!["thumb"]!
But now, after I updated Xcode, it's giving the following error: "Type Int does not conform to protocol 'StringLiteralConvertible'
I have to do the following to work:
let item_thumb = fotos[0] as NSDictionary
var url = item_thumb.objectForKey("foto")!.objectForKey("thumb")!
By the way, using item_thumb["foto"]! as I would use in other places, is also giving me an error: "Type String does not conform to protocol 'NSCopying'"
Can you help me out why it isn't working anymore?
Should be
fotos[0]["foto"]!["thumb"]!
Because first one is array, not dictionary (0 is index, which is of type int, not a key, which is string ).
Related
in the Kotlin language android development application, I try to use Klaxon to convert my list of objects to JSON string.
my code work without error on debugging but after release it has error on JsonArray(queryResult).toJsonString()
error is: No accessors or field is found for property var ea.c.: kotlin.String?
queryResult here is List
is there any special permission I missed to apply for release?
This code is a basic input/output function in Kotlin. But I am facing an issue with syntax even though it is right.
I figured out the mistake here. first of i wanted to take an input an integer type and also a string type which must be provided by the user. so i tried to use scanner instead we could have used val a: Int =readLine()!!.toInt() for integer type. and val b:string=readLine()!! for string type.
I read how to init embed type, and a related Q&A.
What my problem is when compile this code, I got :
[Error] unknown field 'feature.DefaultSshHelper' in struct literal of type dala02
type FDH feature.DefaultSshHelper
type dala02 struct {
Md5_v string
feature.DefaultSshHelper
//FDH
}
var x_01_h1_p = &dala02{
Md5_v: "",
feature.DefaultSshHelper: feature.DefaultSshHelper{
//FDH: FDH{
// blabla
},
}
// use it by a interface []feature.CmdFioHelper{x_00_h1_p}
At first time, I thought it was an Exported problem, so I added this line 'type FDH feature.DefaultSshHelper'. Now, we have this error :
[Error] cannot use x_01_h1_p (type *dala02) as type feature.CmdFioHelper in array or slice literal:
*dala02 does not implement feature.CmdFioHelper (missing Getnextchecker method)
But a pointer of feature.DefaultSshHelper does implement feature.CmdFioHelper ( a interface ). So pointer of dala02 should also implement that, right? (reference form effective go)
There's an important way in which embedding differs from subclassing. When we embed a type, the methods of that type become methods of the outer type, but when they are invoked the receiver of the method is the inner type, not the outer one.
Question is how to fix this compile error, which line is wrong? I'm not a expert for golang, thanks for your advice :). BTW I do find some workaround.
When you refer to embedded fields, you have to leave out the package name of the embedded type, as the unqualified type name acts as the field name.
Spec: Struct types:
A field declared with a type but no explicit field name is an anonymous field, also called an embedded field or an embedding of the type in the struct. An embedded type must be specified as a type name T or as a pointer to a non-interface type name *T, and T itself may not be a pointer type. The unqualified type name acts as the field name.
So simply write:
var x_01_h1_p = &dala02{
Md5_v: "",
DefaultSshHelper: feature.DefaultSshHelper{
// blabla
},
}
Your other attempt type FDH feature.DefaultSshHelper falls short as this type declaration creates a new type with zero methods: the type FDH does not "inherit" the methods of feature.DefaultSshHelper. And thus any type that embeds FDH will also lack methods of feature.DefaultSshHelper.
This is a follow-up on the question Why do I get a list of numbers instead of JSON when using the Twitch API via Rust? If I use the solution suggested in the previous post:
Use the response.get_body() method to get a list of byte number which can be converted to a Result with from_utf8() method.
This returns a Result with everything in it. I'm not sure how to manipulate it. I was hoping I could use it like an array but the docs and rustbyexample don't seem to explain it. What is the purpose of a Result type?
This is the exact response that I'm getting from the body after converting it to UTF-8.
The Result type does not help you here – it just stores arbitrary data and is used for error handling (instead of exceptions). But you can use the rustc_serialize crate to parse the string returned by the Result:
extern crate rustc_serialize;
use rustc_serialize::json::Json;
fn main() {
let response_result = /* ... */;
let data = response_result.unwrap();
let json = Json::from_str(&data).unwrap();
println!("{}", json.find("status").unwrap());
}
I'm trying register presenters with Windsor using the convention based method but trying to do this in VB.NET, but the problem is it does not want to compile this statement:
Dim type = GetType(AbstractPresenter(Of))
I am getting : Too few type arguments to AbstractPresenter(Of TView, TPresenter)
Which I don't understand because this is a valid statement according to question. Also showing valid in other C# to VB.NET converters when converting typeof(AbstractPresenter<>).
Any ideas?
There are two type arguments, and you need to specify this, just as you would do for multi-dimensional arrays:
Dim type = GetType(AbstractPresenter(Of ,))
Looks weird, but now the compiler knows that AbstractPresenter expects two type arguments.
By the way, C# has the same requirement. So the above would be written as:
var type = typeof(AbstractPresenter<,>);