I'm currently using json-framework and need some help though parsing some JSON i'm getting from my server. Here is how the JSON looks:
Like I said I already have the json-framework installed but I can't figure out how to actually parse it. Can someone please show me? Thanks!
[
{
"id":"0",
"name":"name",
"info":"This is info",
"tags":
[
{
"id":"36",
"tag":"test tag",
},
{
"id":"37",
"tag":" tag 2",
}
],
"other":"nil"
},
{
"id":"1",
"name":"name",
"info":"This is info",
"tags":
[
{
"id":"36",
"tag":"test tag",
},
{
"id":"37",
"tag":" tag 2",
}
],
"other":"nil"
}
]
jsonlint.com will help you as far as validation, I don't believe you want the trailing commas. json-framework implements a strict parser.
[
{
"id": "0",
"name": "name",
"info": "This is info",
"tags": [
{
"id": "36",
"tag": "test tag"
},
{
"id": "37",
"tag": " tag 2"
}
],
"other": "nil"
},
{
"id": "1",
"name": "name",
"info": "This is info",
"tags": [
{
"id": "36",
"tag": "test tag"
},
{
"id": "37",
"tag": " tag 2"
}
],
"other": "nil"
}
]
Have a look at the Examples.m file in your json-framework download. Also available here.
The API is available here.
You will probably end up using the NSString and NSObject categories when doing your parsing.
Related
In my application, I have a section of comments and replies under some documents.
Here's how my database schema looks like
db.updates.insertOne({
"_id": "62347813d28412ffd82b551d",
"documentID": "17987e64-f848-40f3-817e-98adfd9f4ecd",
"stream": [
{
"id": "623478134c449b218b68f636",
"type": "comment",
"text": "Hey #john, we got a problem",
"authorID": "843df3dbbdfc62ba2d902326",
"taggedUsers": [
"623209d2ab26cfdbbd3fd348"
],
"replies": [
{
"id": "623478284c449b218b68f637",
"type": "reply",
"text": "Not sure, let's involve #jim here",
"authorID": "623209d2ab26cfdbbd3fd348",
"taggedUsers": [
"26cfdbbd3fd349623209d2ab"
]
}
]
}
]
})
db.users.insertMany([
{
"_id": "843df3dbbdfc62ba2d902326",
"name": "Manager"
},
{
"_id": "623209d2ab26cfdbbd3fd348",
"name": "John"
},
{
"_id": "26cfdbbd3fd349623209d2ab",
"name": "Jim"
},
])
I want to join those two collections, and replace user ids with complete user information on all levels. So the final JSON should look like this
{
"_id": "62347813d28412ffd82b551d",
"documentID": "17987e64-f848-40f3-817e-98adfd9f4ecd",
"stream": [
{
"id": "623478134c449b218b68f636",
"type": "comment",
"text": "Hey #john, we got a problem",
"author": {
"_id": "843df3dbbdfc62ba2d902326",
"name": "Manager"
},
"taggedUsers": [
{
"_id": "623209d2ab26cfdbbd3fd348",
"name": "John"
}
],
"replies": [
{
"id": "623478284c449b218b68f637",
"type": "reply",
"text": "Not sure, let's involve #jim here",
"author": {
"_id": "623209d2ab26cfdbbd3fd348",
"name": "John"
},
"taggedUsers": [
{
"_id": "26cfdbbd3fd349623209d2ab",
"name": "Jim"
}
]
}
]
}
]
}
I know how to do the $lookup on the top-level fields, including pipelines, but how can I do with the nested ones?
I'm reading the Facebook Send API and events docs, and I'm surprised to see some examples define the message at the top level of the JSON object hierarchy (here for "text message")
{
"sender":{
"id":"<PSID>"
},
"recipient":{
"id":"<PAGE_ID>"
},
"timestamp":1458692752478,
"message":{
"mid":"mid.1457764197618:41d102a3e1ae206a38",
"text":"hello, world!",
"quick_reply": {
"payload": "<DEVELOPER_DEFINED_PAYLOAD>"
}
}
}
While others examples have a different object structure:
{
"id": "682498302938465",
"time": 1518479195594,
"messaging": [
{
"sender": {
"id": "<PSID>"
},
"recipient": {
"id": "<PAGE_ID>"
},
"timestamp": 1518479195308,
"message": {
"mid": "mid.$cAAJdkrCd2ORnva8ErFhjGm0X_Q_c",
"attachments": [
{
"type": "<image|video|audio|file>",
"payload": {
"url": "<ATTACHMENT_URL>"
}
}
]
}
}
]
}
Here is seems like the object is the first example is instead contained in a messaging array. I can't find either what id corresponds to in this second example : there is no table detailing the fields on why the hierarchy is different here.
Finally, there is another example with a different structure:
{
"object": "page",
"entry": [
{
"id": "<PAGE_ID>",
"time": 1583173667623,
"messaging": [
{
"sender": {
"id": "<PSID>"
},
"recipient": {
"id": "<PAGE_ID>"
},
"timestamp": 1583173666767,
"message": {
"mid": "m_toDnmD...",
"text": "This is where I want to go: https:\/\/youtu.be\/bbo_fZAjIhg",
"attachments": [
{
"type": "fallback",
"payload": {
"url": "<ATTACHMENT_URL >",
"title": "TAHITI - Heaven on Earth"
}
}
]
}
}
]
}
]
}
Are these differences documented elsewhere? Why do they exist in the first place? Why is messaging an array? Can it contain multiple messages at once?
I'm using Netsuite's Postman collection (which takes care of the Oauth1 stuff), and am POSTing to this endpoint:
{{proto}}://{{host}}/rest/platform/{{version}}/record/salesorder
... and the body is something like this:
{
"customForm": "999",
"entity": {
"id": "1111"
},
"department": {
"id": "2222"
},
"subsidiary": {
"id": "33"
},
"otherRefNum": "TEST-PO",
"location": {
"id": "444"
},
"item": {
"items": [
{
"item": { "id": "555555" },
"inventorylocation": { "id": "444" },
"price": { "id": "-1" },
"grossAmt": 999,
"quantity": 1
}
]
}
}
I'm trying to assign a location on the item level. The above request creates a sales order ok (without the line-level location assignment) if I remove the inventorylocation line, but with that in there, I get this error: Unknown reference or subrecord field inventorylocation in request body.
Netsuite's REST API documentation is here:
https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2019.2/index.html#tag-salesorder
I have also tried substituting location and moving the fields around a bit, without success. (either the salesorder is created without a line-level location assignment, or I get an error similar to the above error.
Any ideas?
From the documentation you linked, it appears that the field id you need is inventorylocation rather than itemlocation.
salesorder-itemElement
...
giftCertRecipientName Recipient Name: string
id [Missing Label:id]: string
inventorydetail: salesorder-item-inventorydetail
inventorylocation: location
inventorysubsidiary: subsidiary
isClosed Closed: boolean
...
Based on the documentation for a salesOrder-itemElement, it looks like that key is correct.
Have you tried the "location": "{ID}" variation?
In LedgerSync it looks like the request for creating an invoice results in this body:
{
"entity": "309",
"location": "1",
"sublist": {
"items": [
{
"amount": 12345,
"description": "Test Line Item FLURYAOLJLFADYGR-1"
},
{
"amount": 12345,
"description": "Test Line Item FLURYAOLUFUTBYJD-2"
}
]
}
}
There also is a salesOrder-item-inventorydetail object that also contains a location. Perhaps you could use that one like so:
{
"customForm": "999",
"entity": {
"id": "1111"
},
"department": {
"id": "2222"
},
"subsidiary": {
"id": "33"
},
"otherRefNum": "TEST-PO",
"location": {
"id": "444"
},
"item": {
"items": [
{
"item": { "id": "555555" },
"inventorydetail": {
"location": "444"
},
"price": { "id": "-1" },
"grossAmt": 999,
"quantity": 1
}
]
}
}
I have developed cloud functions and am using 'generic output' with image response types, as well as text. However when I search for a product (which uses my cloud function), the last result appears.
For example:
Me: Buy Classic now
Bot: Name: Classic, Price: 4.99, Description: Classic description
But when I search for another product
Me: Buy Extra now
the bot will display
Bot: Name: Classic, Price: 4.99, Description: Classic description
Only until another search instance does it refresh and display the correct result.
{
"context": {
"name": "",
"counter": 0
},
"output": {
"generic": [
{
"values": [
{
"text": "Found Products"
}
],
"response_type": "text",
"selection_policy": "sequential"
},
{
"title": "<? $result.body.items[0].name ?>",
"source": "http://**********/pub/media/catalog/product<? $result.body.items[0].custom_attributes[5].value ?>",
"description": "$<? $result.body.items[0].price ?>",
"response_type": "image"
},
{
"title": "Select one of the following options",
"options": [
{
"label": "Order a subscription",
"value": {
"input": {
"text": "Order a subscription"
}
}
},
{
"label": "More Details",
"value": {
"input": {
"text": "More Details"
}
}
}
],
"response_type": "option"
}
]
},
"actions": [
{
"name": "/**********#gmail.com_dev/getProducts2",
"type": "server",
"parameters": {
"url": "<?entities.products[0].literal?>"
},
"credentials": "$my_creds",
"result_variable": "context.result"
}
]
}
Found the answer. I put the output text in a child node instead of the parent node. No need to remove any context variable.
Ideally the call to this API - https://api.surveymonkey.net/v2/surveys/get_responses
should give a json response like this :
{
"data": [
{
"questions": [
{
"answers": [
{
"col": "3024965133",
"row": "3024965139"
},
{
"col": "3024965134",
"row": "3024965140"
},
{
"col": "3024965135",
"row": "3024965141"
},
{
"row": "0",
"text": "Other!"
}
],
"question_id": "316084770"
},
{
"answers": [
{
"col": "3024965125",
"row": "3024965122"
},
{
"col": "3024965124",
"row": "3024965123"
}
],
"question_id": "316084761"
},
{
"answers": [
{
"row": "3024959616"
}
],
"question_id": "316083321"
},
{
"answers": [
{
"row": "0",
"text": "This is an open answer"
}
],
"question_id": "316083320"
},
{
"answers": [
{
"col": "3024962639",
"row": "3024962638"
},
{
"col": "3024962640",
"row": "3024962637"
},
{
"col": "3024962639",
"row": "3024962636"
}
],
"question_id": "316084090"
},
{
"answers": [
{
"row": "3024964761",
"text": "9"
},
{
"row": "3024964762",
"text": "1"
}
],
"question_id": "316084724"
}
],
"respondent_id": "2500019027"
}
],
"status": 0
}
But when I am requesting the API for responses to my survey by specific respondents, I am getting a blank array.
Note : I am able to see the proper responses via SurveyMonkey UI console.
If you use API v3, you may get a better error message:
https://developer.surveymonkey.com/api/v3/#surveys-id-responses
It seems your issue could be that you have more than 100 responses for that survey and you can only access the first 100 on a basic plan from what I see from the logs.
If that's the case the solution would be to
Upgrade your plan
Delete some old responses
Duplicate the survey maybe?
Again I would recommend moving to V3 of the API for a better experience.