I am trying to change cell format to plain text from google api: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate
Doing it directly from google drive gives me a completely different result than doing it from the API.
I add the following examples of what I am trying to do.
This is from the spreadsheet formatting:
This is the field I want to format as plain text
This is what I do
Format > Number > Plain Text
This is the result:
This is what happens when I format it from the google API with the above JSON:
This is the field I want to format:
This is the XML that I am applying from the API:
"requests": [
{
"repeatCell": {
"range": {
"sheetId": 3,
"startColumnIndex": 2,
"endColumnIndex": 3,
"startRowIndex": 16,
"endRowIndex": 17
},
"cell": {
"userEnteredFormat": {
"numberFormat": {
"type": "TEXT"
}
}
},
"fields": "userEnteredFormat.numberFormat"
}
}
]
}```
This is the result of applying the format from the API:
My problem: how can I get the same thing from the API as from the sheet? What do I have to change in the JSON to correctly apply the format?
Related
How can I read this type of json data like I want profession of ID:12311 in google spreadsheet?
{
"user": [
{
"id": 12311,
"name": "Deffy doof",
"profession": "Photographer"
},
{
"id": 18341,
"name": "John Smith",
"profession": "Developer"
}
]
}
Solution:
Since this is an array of objects you can reference elements using array notation, e.g., to pull "Photographer":
data.user[0].profession
Sample:
If you only know the unique ID and not the index, you can filter the array first, then get the element.
var array = data.user.filter(function b(e) { return e.id == 12311 });
console.log(array[0].profession);
References:
filter()
I've got this JSON data (not verbatim) that I get from the backend. It contains the actual data and an array of strings describing the sequence of cells to be shown:
{
"data": [
{
"name": "text",
"data": {
"text": "some text"
}
},
{
"name": "pic",
"data": {
"url": "https://somepic.jpg",
"text": "picture"
}
},
{
"name": "switcher",
"data": {
"id": 1,
"options": [
{
"id": 0,
"text": "option 1"
},
{
"id": 1,
"text": "option 2"
},
{
"id": 2,
"text": "option 3"
}
]
}
}
],
"view": [
"text",
"pic",
"switcher",
"text"
]
}
The problem is that I can't get my head around how to configure cellForRowAt: and get the right order of cells in one section. (i.e. text, pic, selector, text).
I tried a couple of things:
Looping through "view" array and switching on each individual view string to dequeue a specific cell but that doesn't seem to work since returning a cell from a switch case gives a "unexpected non-void return value in void function" error.
I was also thinking about turning a "view" array into a dictionary and then, based on keys in it, dequeue a specific cell but then again, a dictionary should have unique keys meaning that I will not have 2 "text" entries, one of them will be lost.
So, the questions is: how can I dequeue specific cells based on the array of strings? It's also important to understand that it should be done in one section. I'm feeling that it's somehow not that difficult to implement but I'm kinda lost right now. Thanks!
you need to transform your view list and data array into an array of cell contents that you can use inside the TableViewDelegate and TableViewSource method :
var cellsContents : [Int] = []
for aView in view {
var found = false
var index = 0
for aData in data {
if !found {
if let name = aData["name"] as? String {
if aView == name {
found = true
cellsContents.append(index)
continue
}
}
index = index + 1
}
}
}
Then :
number of rows : cellsContents.count
type and contents for a row : data[cellsContents[indexPath.row]]["name"] and data[cellsContents[indexPath.row]]["data"]
how to assert the json response array contains a substring in a string value.
I have tried this but assertion is failed response.then().body("response.content.Date", Matchers.everyItem(contains("2019-03") ));
my response body is
{
"response": {
"totalSize": 2,
"content": [
{
"requestId": " 931-f8222e",
"name": "gowtham",
"date": "2019-03-06",
"issue": "i have a cause"
},
{
"requestId": " 931-f8222e",
"name": "tharun",
"date": "2019-03-09",
"issue": "has a issue in billing"
}
]
}
}
i want to get all the records in the month(value) and assert the response showing data for given month
I found the solution. You were very close. Instead of using contains which matches full string, you can use containsString to match a substring.
Code:
response.then().body("response.content.date", Every.everyItem(Matchers.containsString("2019-03")));
I need to send data over socketio from ios using swift. Data looks like this:
{
birthday: {
"date": 24,
"month": 12,
"year": 1991
}
}
I tried this code, but it doesn't work:
let myJSON = [
"birthday" : [
"date": 24,
"month": 12,
"year": 1991
]
]
socket.emit("updateUserInfo", myJSON)
Please, tell me what i'm doing wrong
January 2020
Asumming that you are using Socket.IO-Client-Swift Library
Here is the sample source on how to effectively pass your JSON data.
// Adopt to SocketData protocol
struct CustomData : SocketData {
let name: String
let age: Int
func socketRepresentation() -> SocketData {
return ["name": name, "age": age]
}
}
// Usage
socket.emit("myEvent", CustomData(name: "Erik", age: 24))
You are right that if you have a dictionary to send over socket.io then you don't have to convert it to JSON because the method socket.emit does that for you.
So the syntax you show seems to be correct : socket.emit("event-as-string", dictionary).
You should tell us the exact error you are encountering such as someone can help you.
With socket.io you can send a normal object from javascript and it will be converted to JSON automatically.
I tested that code and everything is ok
let myJSON = { birthday: { "date": 24, "month": 12, "year": 1991}};
socket.emit("updateUserInfo", myJSON);
I believe you'll need to convert your Swift object to a JSON string. As Eric D. said there's a built in way to convert dictionary to JSON. If you already have a class representation of the data, you can take a look at a Swift class to JSON converter here:
https://gist.github.com/peheje/cc3618253d4f38ea4885
Have you tried just writing it as a string?
let myJSON = "[\"birthday\" : [\"date\": 24, \"month\": 12, \"year\": 1991]]"
Try this may work , internally it's getting object from zero index
[{
birthday: {
"date": 24,
"month": 12,
"year": 1991
}
}]
I have the following data structure Snapshot which is a combination of nested arrays and dictionaries:
{"Snapshot": {
"ask": [
{
"price": 101.42,
"size": 7
},
{
"price": 101.85,
"size": 5
}
],
"bid": [
{
"price": 89.72,
"size": 79
},
{
"price": 89.71,
"size": 158
}
]
}}
The existing structure from above should be updated by the price and size entries in the following dictionary / array structure:
{"Refresh": {
"ask": [],
"bid": [
{
"price": 89.71,
"size": 666
}
],
}}
In this example, the value size for the bid item which has the price: 89.71 should be updated from 158 to 666. If the price does not exist yet, a new item with the price and size from the Refresh data structure should be added. If size = 0, the price and size item should be removed.
I have tried to do this with the methods addEntriesFromDictionary and addObjectsFromArray but did find a solution to my problem.
What would be the fastest way to do this?
How would you recommend to merge these two data structures?
Thank you!
Assuming the dictionaries are named snapshot and refresh...
snapshot[#"Snapshot][#"bid"] = [snapshot[#"Snapshot][#"bid"] arrayByAddingObjectsFromArray:refresh[#"Refresh"][#"bid]];
More complicated union of the arrays will just require more code. And if you want price to be a unique key, why not make it a key?