making this query:
dbus-send --system --print-reply --dest=org.ofono /he910_0 org.ofono.ConnectionManager.GetContexts
I get the following structure:
array [
struct {
object path "/he910_0/context1"
array [
dict entry(
string "AccessPointName"
variant string "mobile.vodafone.it"
)
....
dict entry(
string "Settings"
variant array [
]
)
]
}
I'd like to set "Settings" property with dbus-send messages. I tried with:
dbus-send --system --print-reply --dest=org.ofono /he910_0/context1 org.ofono.ConnectionContext.SetProperty string:"Settings" variant:array:string:"Interface=ppp0","Method=dhcp"
But I receive:
dbus-send: Unknown type "array"
So, the final question is: how to set a variant array through dbus-send ?
You can't do this with dbus-send, but you might be able to do what you want with the quite similar tool gdbus. See how to use parameters signature as "a{sv}" in dbus-send
Related
if I try to use axios.put to save a string, it will give an error 400: Invalid data; couldn't parse JSON object, array, or value.
For example:
axios.put('firebase/url/example.json', "some string")
But if I use a integer, it will work perfectly:
axios.put('firebase/url/example.json', 200)
How can I save a string using put?
Firebase will try to parse "some string" using a JSON.parse-like function.
If you try it yourself, you will not be able to parse this:
JSON.parse("some string")
But if you encode the string properly, you will see it gets wrapped in more quotes:
console.log(JSON.stringify("some string"))
console.log("some string")
// will output:
// 1. "some string"
// 2. some string
The Firebase API docs highlight this with this example:
curl -X PUT -d '"Alan Turing"' \
'https://docs-examples.firebaseio.com/rest/saving-data/fireblog/users/alanisawesome/name.json'
So all you need to do is properly parse the data beforehand:
axios.put('firebase/url/example.json', JSON.stringify("some string"))
The reason 200 works, is that it's a single number which can be directly read by a JSON parser.
I have a method that returns a JsArray of a type Foo.
To process the response, I am doing the following:
val foos : List[Foo] = Json.toJson(result).as[List[Foo]]
While debugging, I could see that the result is comming as:
"[]"
and it is generated by the code:
Ok(Json.toJson(foos))
Where foos is a List[Foo]
But I am getting the error:
[JsResultException: JsResultException(errors:List((,List(ValidationError(error.expected.jsarray,WrappedArray())))))]
I've tried many ways, but can't solve this.
What I am doing wrong?
You're most likely looking for Json.parse, rather than Json.toJson.
import play.api.libs.json.Json
scala> Json.toJson("[]")
res0: play.api.libs.json.JsValue = "[]"
scala> Json.parse("[]")
res1: play.api.libs.json.JsValue = []
Trying to convert res0 to a List[Foo] doesn't work because you're trying to convert the string "[]" rather than than the same string without quotation marks, [].
It seems like you have it the wrong way around. Json.toJson(value) is used to convert from a Scala object to a JSON value. You are using it incorrectly to try and read a JSON body and convert it to a Scala object. You probably want to do something like this:
val foos : JsResult[List[Foo]] = result.validate[List[Foo]]
where result is your JSON value.
Look at this, under the 'JsValue to a model' section:
https://www.playframework.com/documentation/2.6.x/ScalaJson
Let us assume my my psake default.ps1 looks like this :
properties { $dllsToMerge= #("x.dll","y.dll")}
task ilmerge {
exec { &ilmerge -dll $dllsToMerge -out single.dll}
}
now when running this task at some times I would like to change which assemblies get merged. For example :
invoke-psake ilmerge -properties #{"dllsToMerge"="#("x.dll","y.dll","z.dll")"}
for some reason the above command does not work as it is not able to parse the string as array. Any way to do this without manual parsing and string to array conversion ?
the below is the sample code in swift.
var loadedMessages = [[Message]]()
Message is a custom class. i'm not sure what [[Message]] () is doing.
It is specifying that your variable loadedMessages is an array of arrays that contains Message objects. A JSON representation of loadedMessages might look like:
loadedMessages: [
[ <Message>, <Message>, <Message> ],
[ <Message>, <Message>, <Message> ]
]
A quick Playground implementation of something similar can give you a pretty good introspection of the situation:
var foo = [[String]]()
foo.append(["bar"])
foo[0][0] // reveals "bar"
It means it’s an array of arrays of messages. Think of it in terms of whatever appears between the square brackets being an array of that, and this can include another array.
Alternatively, if you were to write out without the “shorthand” array syntax, it would be Array<Array<Messages>>().
I am just learning the basics in VB 2010, and I am trying to design a program to maintain a database. I have a JSON string in the database that contains a list of image files and their relevant ID numbers. This is in JSON as a website also uses this data.
The example code is
[{"ID": 0, "Path": "Image0.jpg"},{"ID": 1, "Path": "Image1.jpg"}, {"ID": 2, "Path": "Image2.jpg"},{"ID": 3, "Path": "Image3.jpg"}]
I have tried using JSON.NET, but I am a novice and don't know why it isn't working.
I wish for there to be a way I can return the image files, for example in php $DecodedArray[0] would work, I am looking for a way to replicate this in Visual Basic.
Imports System.Web.Script.Serialization
Module Module1
Public Class Target
Public ID, Image As String
End Class
Sub Main()
Console.Clear()
Dim ser As New JavaScriptSerializer()
Dim input As String = My.Computer.FileSystem.ReadAllText("JSONFile.txt")
'[{"ID": 0, "Path": "Image0.jpg"},{"ID": 1, "Path": "Image1.jpg"}, {"ID": 2, "Path": "Image2.jpg"},{"ID": 3, "Path": "Image3.jpg"}]
Console.WriteLine(input)
Console.WriteLine()
Dim output As Target = ser.Deserialize(Of Target)(input)
Console.Write(output.ID.0)
Console.ReadKey()
End Sub
End Module
With this code, I would like the output to be Image0.jpg
Note, I cannot upgrade from Visual Basic 2010 Express
Because your JSON has numeric keys instead of expected keys, it would be difficult to define a custom type to match it. I believe your best bet is to deserialize into a Dictionary(Of String, String) - this will deserialize properly, and you can read through the dictionary to get your items.
So:
Dim output = ser.Deserialize(Of Dictionary(Of String, String))(input)
For Each key As String In output.Keys
Console.WriteLine("{0}: {1}", key, output(key))
Next
Normally when you define a regular type, you'd have to know the names of the JSON properties. Given your Target class, your JSON would actually look like:
[
{ "ID":"0", "Image":"Image0.jpg" },
{ "ID":"1", "Image":"Image1.jpg" },
{ "ID":"2", "Image":"Image2.jpg" }
]
And it would deserialize into an array of Target objects, rather than a single one. But if you're stuck with the JSON that you've got, the Dictionary is the way to go.
If you're able to use the cleaner JSON from here, your code is just about right. You just deserialize into an array instead, and you can access elements of that array. So:
Dim output = ser.Deserialize(Of Target())(input)
For i As Integer = 0 To output.GetUpperBound(0)
Console.WriteLine("{0}: {1}", output(i).ID, output(i).Image)
Next