I am trying to make a simple twitter client in C. I'm new at this and not sure how to go about segregating meaningful stuff from the JSON string that I get from the API.
For example, if I get this as a response from the API, how do I extract out the value of "text" into a string (char*)? I guess I can work with the string at low level, but wouldn't that become too tedious every time I need to get a value from the JSON string?
For JSON in general, json.org has a big list of parsers implemented in a ton of different languages.
For C:
JSON_checker
JSON parser
json-c
M's JSON parser
YAJL
cJSON
Jansson
jsmn
Why not just use one of the existing libraries for working w/ Twitter?
http://apiwiki.twitter.com/Libraries
As a more direct response to your question, I'd recommend not trying to do text parsing on your own, but instead have classes that mean something to your domain that you can then use the JSON serialization/deserialization logic that comes w/ the framework, e.g.
http://msdn.microsoft.com/en-us/library/bb412179.aspx
Hope that helps,
Paul
Related
I don't know what kind of format is inside the JSON-LD, but it needs to be converted into a well-defined object.
My question is I don't know what kind of JSON-LD data is uploaded by the client and I don't know if it is possible to convert such data into some object with a well-defined format.
Do you have a solution yet?
If you don't know the structure of the object beforehand, you will probably have to use some generic structure to hold the data in Java. If you use a library like jsonld-java, it will do exactly that. You will work with Maps and Lists and it should be able to accommodate basically any JSON-LD data.
If you did know the target structure (for example, if it were one of several types for which you have a Java class), you could use a library like JB4JSON-LD to load it into an object of that class.
Disclaimer: I am the author of the JB4JSON-LD library.
Could someone point me in the right direction please?
I am trying to extract specific text/numbers from a json payload. I can access/isolate the full string of text by using triggerFormDataValue('text').
The text in question may contain 'sendSMS 1122334455 actual message' as its actual value
Is there anyway, in a logic app flow, to break the text into its component parts?
(sendsms, 1122334455 and actual message)
n.b. I have already tried interacting with the cognitive analysis app for key word searches but that doesn't return the number, nor the full sting, just the key words.
thanks
For more complex logic like the one you have, I would recommend to create an Azure Function. This is a light-weight solution that will offer you the flexibility of a microservice which offers you this possibility.
To extract the numbers, you may use a regular expression.
Edit:
I've found a similar question here on SO, but the conclusion is very similar.
I've done some small research now and it seems Microsoft deliberately does't put too much text parsing functionality in Logic Apps in order to avoid them being too complex. You might have a chance if you put them in JSON notation, but I think the better option would be to go to Azure functions, since it provides reuseability as well.
If that's all you need to do, you can use the split() function. Details: String Functions...split
I have a recurring problem with single-item json data sources that are consistently rejected by a C data parser looking for the parent/child structure of a multi-item feed.
Where is it easiest to fix this - on my end, when I create the feeds, or for the C programmer to add a couple lines to also let it accept data that looks like object?
The error message I get is
Cannot access child value on Newtonsoft.Json.Linq.JProperty
which tells me it looks around the house for children that don't exist, like a nosy aunt.
In case you need to know how the data is processed, I use yql to standardize various sources so the parser can import everything into the right MongoDB fields. Everything is generated dynamically a few times a day and I can't do anything about the sources that will only deliver one update at a time.
Here's an example of json rejected because it looks like an object.
{"item":
{
"artist":"Morphine",
"song":"Thursday",
"station":"WXXX",
"feeddate":"1438014574000",
"dttype":"utc"
}
}
The one whose fault it is, has to fix it. Simple. Look up the specification what you are allowed to pass to the parser.
I'm developing a REST API based on the HAL specification. The API is being developed in PHP with Symfony and the client is being build in angularjs. The API must return some lists and they are going to be shown using ngtables library, and filtering options will be needed, ideally in the format that ngtables uses, like in this sample.
{ "name": "M", "age": "4" }
(Of course future clients may be use the same options.)
My frontend-workmate is suggesting me to send the json encoded directly as a parameter in the url, like this:
?filter=%7B%20%22name%22%3A%20%22M%22%2C%20%22age%22%3A%20%224%22%20%7D%20
I'm not very sure about that though.
I've been reading how to send arrays through the URL with a parameter like param[]=foo¶m[]=bar but that does implies have one key for multiple values. In my case I need to be able to send different key-values for the arrays like a Json object does.
I'm wondering how should be the Request URL from the client to be able to include all the filter options inside one parameteror and if there is any standard way to do that.
EDITED: After #Ross_Turner I want to clarify that my intention of passing a key-value array inside a parameter is because we'll have another type of parameter. For example:
?filter=<my key-value array>&page=1&limit=50&anotherParam=whatever
Even we would like to use another parameter containing another key-value array like this:
?filter=<my key-value array>&sorting=<another key-value array>&page=1&limit=50
Where filter and sorting can have the same keys.
Currently there is no standard way to send queries in GET requests. So you have 2 options: you use your custom query language (like you already tried) or you choose a standard query language. Either way it is hard to make it RESTful, because you have to create a link, which contains a recipe how to generate such an URI. You can probably use URI templates, but sometimes they are not general enough...
#Ross Turner:
I think you misunderstood, I was talking about not having a standard. Ofc. there are non standard query string based solutions, for example RQL. Or you can send a standard SPARQL query in a single param, but there is no standard way to describe such a link, and without link descriptions you cannot generate the query in a REST client, so it won't be loosely coupled and so it will violate the uniform interface constraint.
I disagree with #inf3ero's answer - surely there is a very well defined way to send a query as part of a GET request - query parameters. If you want different key and value combinations this is the principal of the keys and values of query parameters, so in your example you should probably use ?name=M&age=4 and parse each of these on your server. It should be simple enough to convert
{ "name": "M", "age": "4" }
into this by iterating over the keys in the JSON object. I'm not sure why you would want to combine these into a single parameter if you are attempting to implement a RESTful API following the HAL specification.
I want to serialize all of the data in my realtime document to a string with which I can later initialize a new realtime document. I want to do this so my users can make copies of their drive files, save different versions, etc, and I can re-initialize the relevant realtime documents from the string.
I see I can call document.getModel().getRoot().toString() to get a string representation of the root CollaborativeMap, but I don't see any easy way to load that string back IN to a CollaborativeMap. Also, the string returned is not JSON, so I can't easily use JSON.parse to turn it back into a normal JS object and iterate from there.
I can make this work by hand. Is there any easy automated way?
You can do that on the service side using the realtime.get() and update() methods:
https://developers.google.com/drive/v2/reference/realtime