I am receiving json string through an API from a website. However, the json format sent to me is not the format i want to work with. I want to change the received json string format to the desirable format.
This is the format i received:
{"symbols_returned":147,"base":"USD","data":{"AED":
3.673010,"AFN":75.392000,"ALL":109.685000}}
This however is the format i desire to have:
{"symbols_returned":147,"base":"USD","data":{"AED":"3.673010","AFN":"75.392000","ALL":"109.685000"}}
The difference between the former and latter is the presence of quotation marks on all the numeric currency values in the second json string. It can be seen that the first json string does not have quotes on the numeric currency values.
My question is how can i programmatically turn the first json string to the second json string format using dart programming language. Any help will be appreciated. Thanks
you need to parse the json data before you can use it.
you need to use the json package from dart:convert do do this
import 'dart:convert';
final yourResult = json.decode(API_RESULT);
print(yourResult) // {"symbols_returned":147,"base":"USD","data":{"AED":"3.673010","AFN":"75.392000","ALL":"109.685000"}}
will parse the json and preserve the data types and make that a Map
Related
I have to pass multiple records from a SQL source to the body of a web call in Data Factory in JSON format.
eg.
{"EmployeeCode":"1234",""FirstName":"Joe","LastName":"Bloggs"}
{"EmployeeCode":"5678",""FirstName":"Jack","LastName":"Ryan"}
However, I cannot seem to do it without ADF adding escape characters "\".
{\\"EmployeeCode\\":\\"1234\\",\\"\\"FirstName\\":\\"Joe\\",\\"LastName\\":\\"Bloggs\\"}"
So far I have tried:
Copy activity - Formatted SQL as JSON
Copy activity - SQL output to BLOB JSON
Copy activity - SQL concatenated string output
Does anyone have a process by which to achieve this? I am hoping I have missed something easy.
Thanks in advance....
Escape character backslash \ appears wherever double quotes " are used in the string in the Azure data factory.
Thank you #GregGalloway for your valuable input in the comments sections. As #GregGalloway mentioned, convert the string to JSON format in the web body as shown in the below example.
Example:
Source: SQL data
Getting SQL records using lookup activity.
Passing the output record to web activity in JSON format.
#json(activity('Lookup1').output.value[0].description)
The input of the web activity body is shown as below in JSON format:
I am trying to get the string representation of the HL7 message input to a channel. Documentation says
var myMessage = connectorMessage.getRawData()
should give me the original unparsed HL7 message. However the type of the data returned is an object and not a string. I tried using .toString() but that doesn't work either. My javascript library code that expects a string and be able to split it fails because what's returned is not a string.
How do I get the original HL7 message string?
connectorMessage.getRawData() returns a Java string rather than a javascript string. You can convert to a javascript string by doing.
var myMessage = String(connectorMessage.getRawData())
This is true no matter what you have selected for your data type.
On the Summary tab, click on "set data types", and change your inbound connector to "Raw"....after this, connectorMessage.getRawData() should return to you a long string that is the incoming message.
When I try to parse ( http://www.roundmenu.com/webservices/index.cfm?ws=listrst&filter=featured ) webservice in json I encounter issues.
If any one can find out what the problem please let me know.
thanks in advance.
That’s not valid JSON. As usual, it’s useful to validate JSON input via http://jsonlint.com.
That particular JSON input fails to properly escape double quotes (\") inside strings.
Put the response in a json formatter like this one on curiousconcept.com. It yields many errors, does look like it's invalid json.
I have some string values that are retrieved from json data. I need a process of converting this strings to xml format and Post it to a url
If it's inside iPhone SDK you will have to parse the string to convert it to XML, unless you can just post the xml as-is.
Anyway. To parse the XML, you have basically two easy options:
NSXMLParser
libxml2 (my preferred choice, don't know why)
Then you can use NSURLConnection class to post the information to the desired XML. There are a lot of Stackoverflow questions already covering this issue you can search and use.
You can also look at an example here.
I am working with the iPhone SDK and I have to process a webservice response I receive from an external service.
The response data consists of an XML string that was UTF8-encoded to a byte array.
This byte array is converted to string
This string is put into a XML wrapper element
The wrapper is returned via an HTTP response
Therefore I need to know how to convert the response data back to the XML string it used to be. Unfortunately, I cannot change the way my response is created, so I have to deal with it somehow.
Example of the raw data I get from the webservice:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body><ExportBytesResponse xmlns="http://knowledgepark-ag.com/webservices/">
<ExportBytesResult>PERhdGE+PFJlY29yZCBEQj0iOTk5OTQiIEtleT0iMjA1Mjc0Ij48U2luZ2xlIEl0ZW1JZD0iQVJCUEFLRVQiIFZhbHVlPSIyOTAiIC8+PFNpbmdsZSBJdGVtSWQ9IkhET0tOUiIgVmFsdWU9IjIwNTI3NCIgLz48U2luZ2xlIEl0ZW1JZD0iVkVSQSIgVmFsdWU9IjEuNzEuMzIxMy4xNzU3NyIgLz48U2luZ2xlIEl0ZW1JZD0iRElTIiBWYWx1ZT0iR2VNLCBNw6RyIDEwIDIwMDggIDU6NDFQTTomI3hEO1ouenQuIGV4aXNpdGVydCBrZWluZSBNw7ZnbGljaGtlaXQgZGFzIEJlZW5kZW4gZWluZXMgTW9kdWxzIGR1cmNoIEFiYnJlY2hlbiBvZGVyIEhhcmQtQ2xvc2UtWCB6dSBlcmZhaHJlbi4gQW4gZGllc2VyIFN0ZWxsZSBtw7xzc3RlbiBtZWlzdCBVc2VydmFycyBkZXMgTW9kdWxzIGdlbMO2c2NodCB3ZXJkZW4uIE9kZXIgYW5kZXJlIEF1ZnLDpHVtYWt0aW9uIGR1cmNoZ2Vmw7xocnQgd2VyZGVuLiYjeEE7RUxLRUcgMDYuMDguMjAwOCAwOToyMToxNyYjeEE7JiN4QTsgQmVpc3BpZWxhdWZiYXUgOiYjeEQ7JiN4QTsmbHQ7Q2xv</ExportBytesResult>
</ExportBytesResponse></s:Body>
How do I get back my old xml string representation hidden inside these raw bytes?
Any help is highly appreciated, I feel just stupid right now for not being able to come up with a solution.
Best Regards,
David
ExportBytesResponse is Base64 encoded, so you must first decode that node using something like this.
That will give you an NSString containing the XML. Then you can use NSXMLParser to parse your data.