Google currency api in android [duplicate] - android

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
Now, I did find the Google Finance API and started looking through that but I found a lot of info about portfolios, transactions, positions & other stuff I know nothing about.
Am I looking at the wrong docs? What do I need to do to get a feed of exchange rates from GF? Is this even possible?
EDIT
To make things a little clearer. I'm not interested in technical stuff nor do I want any code.

Thanks for all your answers.
Free currencyconverterapi:
Rates updated every 30 min
API key is now required for the free server.
A sample conversion URL is: http://free.currencyconverterapi.com/api/v5/convert?q=EUR_USD&compact=y
For posterity here they are along with other possible answers:
Yahoo finance API Discontinued 2017-11-06###
Discontinued as of 2017-11-06 with message
It has come to our attention that this service is being used in
violation of the Yahoo Terms of Service. As such, the service is being
discontinued. For all future markets and equities data research,
please refer to finance.yahoo.com.
Request: http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=USDINR=X
This CSV was being used by a jQuery plugin called Curry. Curry has since (2017-08-29) moved to use fixer.io instead due to stability issues.
Might be useful if you need more than just a CSV.
(thanks to Keyo) Yahoo Query Language lets you get a whole bunch of currencies at once in XML or JSON. The data updates by the second (whereas the European Central Bank has day old data), and stops in the weekend. Doesn't require any kind of sign up.
http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("USDEUR", "USDJPY", "USDBGN", "USDCZK", "USDDKK", "USDGBP", "USDHUF", "USDLTL", "USDLVL", "USDPLN", "USDRON", "USDSEK", "USDCHF", "USDNOK", "USDHRK", "USDRUB", "USDTRY", "USDAUD", "USDBRL", "USDCAD", "USDCNY", "USDHKD", "USDIDR", "USDILS", "USDINR", "USDKRW", "USDMXN", "USDMYR", "USDNZD", "USDPHP", "USDSGD", "USDTHB", "USDZAR", "USDISK")&env=store://datatables.org/alltableswithkeys
Here is the YQL query builder, where you can test a query and copy the url: (NO LONGER AVAILABLE)
http://developer.yahoo.com/yql/console/?q=show%20tables&env=store://datatables.org/alltableswithkeys#h=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22USDMXN%22%2C%20%22USDCHF%22%29
Open Source Exchange Rates API
Free for personal use (1000 hits per month)
Changing "base" (from "USD") is not allowed in Free account
Requires registration.
Request: http://openexchangerates.org/latest.json
Response:
<!-- language: lang-js -->
{
"disclaimer": "This data is collected from various providers ...",
"license": "all code open-source under GPL v3 ...",
"timestamp": 1323115901,
"base": "USD",
"rates": {
"AED": 3.66999725,
"ALL": 102.09382091,
"ANG": 1.78992886,
// 115 more currency rates here ...
}
}
currencylayer API
Free Plan for 250 monthly hits
Changing "source" (from "USD") is not allowed in Free account
Requires registration.
Documentation: currencylayer.com/documentation
JSON Response:
<!-- language: lang-js -->
{
[...]
"timestamp": 1436284516,
"source": "USD",
"quotes": {
"USDAUD": 1.345352401,
"USDCAD": 1.27373397,
"USDCHF": 0.947845302,
"USDEUR": 0.91313905,
"USDGBP": 0.647603397,
// 168 world currencies
}
}
CurrencyFreaks API
Free Plan (1000 hits per month)
Changing 'Base' (From 'USD') is not allowed in free account
Requires registration
Data updated every 60 sec.
179 currencies worldwide including currencies, metals, and cryptocurrencies
Support (Even on the free plan) Shell,Node.js, Java, Python, PHP, Ruby, JS, C#, C, Go, Swift.
Documentation: https://currencyfreaks.com/documentation.html
Endpoint:
$ curl 'https://api.currencyfreaks.com/latest?apikey=YOUR_APIKEY'
JSON Response:
{
"date": "2020-10-08 12:29:00+00",
"base": "USD",
"rates": {
"FJD": "2.139",
"MXN": "21.36942",
"STD": "21031.906016",
"LVL": "0.656261",
"SCR": "18.106031",
"CDF": "1962.53482",
"BBD": "2.0",
"GTQ": "7.783265",
"CLP": "793.0",
"HNL": "24.625383",
"UGX": "3704.50271",
"ZAR": "16.577611",
"TND": "2.762",
"CUC": "1.000396",
"BSD": "1.0",
"SLL": "9809.999914",
"SDG": 55.325,
"IQD": "1194.293591",
.
.
.
[179 currencies]
}
}
Fixer.io API (European Central Bank data)
Free Plan for 1,000 monthly hits
Changing "source" (from "USD") is not allowed in Free account
Requires registration.
This API endpoint is deprecated and will stop working on June 1st, 2018. For more information please visit: https://github.com/fixerAPI/fixer#readme)
Website : http://fixer.io/
Example request :
[http://api.fixer.io/latest?base=USD][7]
Only collects one value per each day
European Central Bank Feed
Docs:
http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html#dev
Request: http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml
XML Response:
<!-- language: lang-xml -->
<Cube>
<Cube time="2015-07-07">
<Cube currency="USD" rate="1.0931"/>
<Cube currency="JPY" rate="133.88"/>
<Cube currency="BGN" rate="1.9558"/>
<Cube currency="CZK" rate="27.100"/>
</Cube>
exchangeratesapi.io
According to the website: Exchange rates API is a free service for current and historical foreign exchange rates published by the European Central Bank
This service is compatible with fixer.io and is really easy to use: no API key needed - UPDATE: API key is now needed, free tier is 250 requests/mo.
For example (this uses CURL, but you can use your favorite requesting tool):
> curl https://api.exchangeratesapi.io/latest?base=GBP&symbols=USD&apikey=YOUR_KEY
{"base":"GBP","rates":{"USD":1.264494191},"date":"2019-05-29"}
CurrencyApi.net
Free Plan for 1250 monthly hits
150 Crypto and physical currencies - live updates
Base currency is set as USD on free account
Requires registration.
Documentation: currencyapi.net/documentation
JSON Response:
{
"valid": true,
"updated": 1567957373,
"base": "USD",
"rates": {
"AED": 3.673042,
"AFN": 77.529504,
"ALL": 109.410403,
// 165 currencies + some cryptos
}
}
Currency from LabStack
Website: https://labstack.com/currency
Documentation: https://labstack.com/docs/api/currency/convert
Pricing: https://labstack.com/pricing
Request: https://currency.labstack.com/api/v1/convert/1/USD/INR
Response:
```js
{
"time": "2019-10-09T21:15:00Z",
"amount": 71.1488
}
```
1: http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("USDEUR", "USDJPY", "USDBGN", "USDCZK", "USDDKK", "USDGBP", "USDHUF", "USDLTL", "USDLVL", "USDPLN", "USDRON", "USDSEK", "USDCHF", "USDNOK", "USDHRK", "USDRUB", "USDTRY", "USDAUD", "USDBRL", "USDCAD", "USDCNY", "USDHKD", "USDIDR", "USDILS", "USDINR", "USDKRW", "USDMXN", "USDMYR", "USDNZD", "USDPHP", "USDSGD", "USDTHB", "USDZAR", "USDISK")&env=store://datatables.org/alltableswithkeys
currency-api
Free & Blazing Fast response using CDN
No Rate limits
150+ Currencies, Including Common Cryptocurrencies
Daily Updated
Documentation: Link
Request: https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api#1/latest/currencies/eur/jpy.json
Request(Fallback): https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api#1/latest/currencies/eur/jpy.min.json
Response:
{
"date": "2021-10-03",
"jpy": 128.798673
}

The European Central Bank (ECB) also has the most reliable free feed that I know of. It contains approx 28 currencies and is updated at least daily.
http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml
For more formats and tools see the ECB reference page:
http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html

Yahoo has a YQL feature to get a whole bunch of currencies at once in XML or JSON. I've noticed the data is up to date by the minute where the ECB has day old data, and stops in the weekend.
http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("USDEUR", "USDJPY", "USDBGN", "USDCZK", "USDDKK", "USDGBP", "USDHUF", "USDLTL", "USDLVL", "USDPLN", "USDRON", "USDSEK", "USDCHF", "USDNOK", "USDHRK", "USDRUB", "USDTRY", "USDAUD", "USDBRL", "USDCAD", "USDCNY", "USDHKD", "USDIDR", "USDILS", "USDINR", "USDKRW", "USDMXN", "USDMYR", "USDNZD", "USDPHP", "USDSGD", "USDTHB", "USDZAR", "USDISK")&env=store://datatables.org/alltableswithkeys
Here is their query builder, where you can test a query and copy the url:
http://developer.yahoo.com/yql/console/?q=show%20tables&env=store://datatables.org/alltableswithkeys#h=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22USDMXN%22%2C%20%22USDCHF%22%29

If you need a free and simple API for converting one currency to another, try free.currencyconverterapi.com.
Disclaimer, I'm the author of the website and I use it for one of my other websites.
The service is free to use even for commercial applications but offers no warranty. For performance reasons, the values are only updated every hour.
A sample conversion URL is: http://free.currencyconverterapi.com/api/v6/convert?q=EUR_PHP&compact=ultra&apiKey=sample-api-key which will return a json-formatted value, e.g. {"EUR_PHP":60.849184}

Here are some exchange APIs with PHP example.
[ Open Exchange Rates API ]
Provides 1,000 requests per month free. You must register and grab the App ID. The base currency USD for free account. Check the supported currencies and documentation.
// open exchange URL // valid app_id * REQUIRED *
$exchange_url = 'https://openexchangerates.org/api/latest.json';
$params = array(
'app_id' => 'YOUR_APP_ID'
);
// make cURL request // parse JSON
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $exchange_url . '?' . http_build_query($params),
CURLOPT_RETURNTRANSFER => true
));
$response = json_decode(curl_exec($curl));
curl_close($curl);
if (!empty($response->rates)) {
// convert 150 USD to JPY ( Japanese Yen )
echo $response->rates->JPY * 150;
}
150 USD = 18039.09015 JPY
[ Currency Layer API ]
Provides 1,000 requests per month free. You must register and grab the Access KEY. Custom base currency is not supported in free account. Check the documentation.
$exchange_url = 'http://apilayer.net/api/live';
$params = array(
'access_key' => 'YOUR_ACCESS_KEY',
'source' => 'USD',
'currencies' => 'JPY',
'format' => 1 // 1 = JSON
);
// make cURL request // parse JSON
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $exchange_url . '?' . http_build_query($params),
CURLOPT_RETURNTRANSFER => true
));
$response = json_decode(curl_exec($curl));
curl_close($curl);
if (!empty($response->quotes)) {
// convert 150 USD to JPY ( Japanese Yen )
echo '150 USD = ' . $response->quotes->USDJPY * 150 . ' JPY';
}
150 USD = 18036.75045 JPY

You can try geoplugin
Beside the geolocation done by IP (but the IP is the provider IP, so not so accurate), they return currencies also and have a currency converter: see examples.
They have 111 currencies updated.

If you're looking for a ruby based solution for this problem, I recommend using the Google Calculator method a solution similar to the following: http://j.mp/QIC564
require 'faraday'
require 'faraday_middleware'
require 'json'
# Debug:
# require "pry"
country_code_src = "USD"
country_code_dst = "INR"
connection = Faraday.get("http://www.google.com/ig/calculator?hl=en&q=1#{country_code_src}=?#{country_code_dst}")
currency_comparison_hash = eval connection.body #Google's output is not JSON, it's a hash
dst_currency_value, *dst_currency_text = *currency_comparison_hash[:rhs].split(' ')
dst_currency_value = dst_currency_value.to_f
dst_currency_text = dst_currency_text.join(' ')
puts "#{country_code_dst} -> #{dst_currency_value} (#{dst_currency_text} to 1 #{country_code_src})"

Here is one simple PHP Script which gets exchange rate between GBP and USD
<?php
$amount = urlencode("1");
$from_GBP0 = urlencode("GBP");
$to_usd= urlencode("USD");
$Dallor = "hl=en&q=$amount$from_GBP0%3D%3F$to_usd";
$US_Rate = file_get_contents("http://google.com/ig/calculator?".$Dallor);
$US_data = explode('"', $US_Rate);
$US_data = explode(' ', $US_data['3']);
$var_USD = $US_data['0'];
echo $to_usd;
echo $var_USD;
echo '<br/>';
?>
Google currency rates are not accurate google itself says ==> Google cannot guarantee the accuracy of the exchange rates used by the calculator. You should confirm current rates before making any transactions that could be affected by changes in the exchange rates. Foreign currency rates provided by Citibank N.A. are displayed under licence. Rates are for information purposes only and are subject to change without notice. Rates for actual transactions may vary and Citibank is not offering to enter into any transaction at any rate displayed.

For all newbie guys searching for some hint about currency conversion, take a look at this link. Datavoila
It helped med a lot regarding my own project in C#. Just in case the site disappears, I'll add the code below. Just add the below steps to your own project. Sorry about the formatting.
const string fromCurrency = "USD";
const string toCurrency = "EUR";
const double amount = 49.95;
// For other currency symbols see http://finance.yahoo.com/currency-converter/
// Clear the output editor //optional use, AFAIK
Output.Clear();
// Construct URL to query the Yahoo! Finance API
const string urlPattern = "http://finance.yahoo.com/d/quotes.csv?s={0}{1}=X&f=l1";
string url = String.Format(urlPattern, fromCurrency, toCurrency);
// Get response as string
string response = new WebClient().DownloadString(url);
// Convert string to number
double exchangeRate =
double.Parse(response, System.Globalization.CultureInfo.InvariantCulture);
// Output the result
Output.Text = String.Format("{0} {1} = {2} {3}",
amount, fromCurrency,
amount * exchangeRate, toCurrency);

Related

Is there a way to scan images in android studio to make sure they are not graphic? possibly using bitmap? [duplicate]

I am currently developing a website for a client. It consists of users being able to upload pictures to be shown in a gallery on the site.
The problem we have is that when a user uploads an image it would obviously need to be verified to make sure it is safe for the website (no pornographic or explicit pictures). However my client would not like to manually have to accept every image that is being uploaded as this would be time consuming and the users' images would not instantly be online.
I am writing my code in PHP. If needs be I could change to ASP.net or C#. Is there any way that this can be done?
2019 Update
A lot has changed since this original answer way back in 2013, the main thing being machine learning. There are now a number of libraries and API's available for programmatically detecting adult content:
Google Cloud Vision API, which uses the same models Google uses for safe search.
NSFWJS uses TensorFlow.js claims to achieve ~90% accuracy and is open source under MIT license.
Yahoo has a solution called Open NSFW under the BSD 2 clause license.
2013 Answer
There is a JavaScript library called nude.js which is for this, although I have never used it. Here is a demo of it in use.
There is also PORNsweeper.
Another option is to "outsource" the moderation work using something like Amazon Mechanical Turk, which is a crowdsourced platform which "enables computer programs to co-ordinate the use of human intelligence to perform tasks which computers are unable to do". So you would basically pay a small amount per moderation item and have an outsourced actual human to moderate the content for you.
The only other solution I can think of is to make the images user moderated, where users can flag inappropriate posts/images for moderation, and if nobody wants to manually moderate them they can simply be removed after a certain number of flags.
Here are a few other interesting links on the topic:
http://thomas.deselaers.de/publications/papers/deselaers_icpr08_porn.pdf
http://www.naun.org/multimedia/NAUN/computers/20-462.pdf
What is the best way to programmatically detect porn images?
The example below does not give you 100% accurate results but it should help you a least a bit and works out of the box.
<?php
$url = 'http://server.com/image.png';
$data = json_decode(file_get_contents('http://api.rest7.com/v1/detect_nudity.php?url=' . $url));
if (#$data->success !== 1)
{
die('Failed');
}
echo 'Contains nudity? ' . $data->nudity . '<br>';
echo 'Nudity percentage: ' . $data->nudity_percentage . '<br>';
If you are looking for an API-based solution, you may want to check out Sightengine.com
It's an automated solution to detect things like adult content, violence, celebrities etc in images and videos.
Here is an example in PHP, using the SDK:
<?php
$client = new SightengineClient('YourApplicationID', 'YourAPIKey');
$output = $client>check('nudity')>image('https://sightengine.com/assets/img/examples/example2.jpg');
The output will then return the classification:
{
"status": "success",
"request": {
"id": "req_VjyxevVQYXQZ1HMbnwtn",
"timestamp": 1471762434.0244,
"operations": 1
},
"nudity": {
"raw": 0.000757,
"partial": 0.000763,
"safe": 0.999243
},
"media": {
"id": "med_KWmB2GQZ29N4MVpVdq5K",
"uri": "https://sightengine.com/assets/img/examples/example2.jpg"
}
}
Have a look at the documentation for more details: https://sightengine.com/docs/#nudity-detection
(disclaimer: I work there)
There is a free API that detects adult content (porn, nudity, NSFW).
https://market.mashape.com/purelabs/sensitive-image-detection
We've using it on our production environment and I would say it works pretty good so far. There are some false detections though, it seems they prefer to mark the image as unsafe if they are unsure.
It all depends on the level of accuracy you are looking for, simple skin tone detection (like nude.js) will prob get you 60-80% accuracy on a generous sample set, for anything more accurate than that, let's say 90-95%, you are going to need some specialized computer vision system with an evolving model that is revised over time. For the latter you might want to check out http://clarifai.com or https://scanii.com (which I work on)
Microsoft Azure has a very cool API called Computer Vision, which you can use for free (either through the UI or programmatically) and has tons of documentation, including for PHP.
It has some amazingly accurate (and sometimes humorous) results.
Outside of detecting adult and "racy" material, it will read text, guess your age, identify primary colours, etc etc.
You can try it out at azure.microsoft.com.
Sample output from a "racy" image:
FEATURE NAME: VALUE:
Description { "tags": [ "person", "man", "young", "woman", "holding",
"surfing", "board", "hair", "laying", "boy", "standing",
"water", "cutting", "white", "beach", "people", "bed" ],
"captions": [ { "text": "a man and a woman taking a selfie",
"confidence": 0.133149087 } ] }
Tags [ { "name": "person", "confidence": 0.9997446 },
{ "name": "man", "confidence": 0.9587285 },
{ "name": "wall", "confidence": 0.9546831 },
{ "name": "swimsuit", "confidence": 0.499717563 } ]
Image format "Jpeg"
Image dimensions 1328 x 2000
Clip art type 0
Line drawing type 0
Black and white false
Adult content true
Adult score 0.9845981
Racy true
Racy score 0.964191854
Categories [ { "name": "people_baby", "score": 0.4921875 } ]
Faces [ { "age": 37, "gender": "Female",
"faceRectangle": { "top": 317, "left": 1554,
"width": 232, "height": 232 } } ]
Dominant color background "Brown"
Dominant color foreground "Black"
Accent Color #0D8CBE

Moving a chat server application from parse.com to google app engine

We are planning to move a chat server application resides on parse.com to Google app engine's datastore since parse is going to shutdown it's service on Jan 2017. I think this should be possible through App engine's XMPP API. Not sure, I love to hear from you..
Currently I'm testing with this code provided by Google
# Copyright 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Crowdguru sample application using the XMPP service on Google App Engine."""
import datetime
from google.appengine.api import datastore_types
from google.appengine.api import xmpp
from google.appengine.ext import ndb
from google.appengine.ext.webapp import xmpp_handlers
import webapp2
from webapp2_extras import jinja2
PONDER_MSG = 'Hmm. Let me think on that a bit.'
TELLME_MSG = 'While I\'m thinking, perhaps you can answer me this: {}'
SOMEONE_ANSWERED_MSG = ('We seek those who are wise and fast. One out of two '
'is not enough. Another has answered my question.')
ANSWER_INTRO_MSG = 'You asked me: {}'
ANSWER_MSG = 'I have thought long and hard, and concluded: {}'
WAIT_MSG = ('Please! One question at a time! You can ask me another once you '
'have an answer to your current question.')
THANKS_MSG = 'Thank you for your wisdom.'
TELLME_THANKS_MSG = THANKS_MSG + ' I\'m still thinking about your question.'
EMPTYQ_MSG = 'Sorry, I don\'t have anything to ask you at the moment.'
HELP_MSG = ('I am the amazing Crowd Guru. Ask me a question by typing '
'\'/tellme the meaning of life\', and I will answer you forthwith! '
'To learn more, go to {}/')
MAX_ANSWER_TIME = 120
class IMProperty(ndb.StringProperty):
"""A custom property for handling IM objects.
IM or Instant Message objects include both an address and its protocol. The
constructor and __str__ method on these objects allow easy translation from
type string to type datastore_types.IM.
"""
def _validate(self, value):
"""Validator to make sure value is an instance of datastore_types.IM.
Args:
value: The value to be validated. Should be an instance of
datastore_types.IM.
Raises:
TypeError: If value is not an instance of datastore_types.IM.
"""
if not isinstance(value, datastore_types.IM):
raise TypeError('expected an IM, got {!r}'.format(value))
def _to_base_type(self, value):
"""Converts native type (datastore_types.IM) to datastore type (string).
Args:
value: The value to be converted. Should be an instance of
datastore_types.IM.
Returns:
String corresponding to the IM value.
"""
return str(value)
def _from_base_type(self, value):
"""Converts datastore type (string) to native type (datastore_types.IM).
Args:
value: The value to be converted. Should be a string.
Returns:
String corresponding to the IM value.
"""
return datastore_types.IM(value)
class Question(ndb.Model):
"""Model to hold questions that the Guru can answer."""
question = ndb.TextProperty(required=True)
asker = IMProperty(required=True)
asked = ndb.DateTimeProperty(required=True, auto_now_add=True)
suspended = ndb.BooleanProperty(required=True)
assignees = IMProperty(repeated=True)
last_assigned = ndb.DateTimeProperty()
answer = ndb.TextProperty(indexed=True)
answerer = IMProperty()
answered = ndb.DateTimeProperty()
#staticmethod
#ndb.transactional
def _try_assign(key, user, expiry):
"""Assigns and returns the question if it's not assigned already.
Args:
key: ndb.Key: The key of a Question to try and assign.
user: datastore_types.IM: The user to assign the question to.
expiry: datetime.datetime: The expiry date of the question.
Returns:
The Question object. If it was already assigned, no change is made.
"""
question = key.get()
if not question.last_assigned or question.last_assigned < expiry:
question.assignees.append(user)
question.last_assigned = datetime.datetime.now()
question.put()
return question
#classmethod
def assign_question(cls, user):
"""Gets an unanswered question and assigns it to a user to answer.
Args:
user: datastore_types.IM: The identity of the user to assign a
question to.
Returns:
The Question entity assigned to the user, or None if there are no
unanswered questions.
"""
question = None
while question is None or user not in question.assignees:
# Assignments made before this timestamp have expired.
expiry = (datetime.datetime.now()
- datetime.timedelta(seconds=MAX_ANSWER_TIME))
# Find a candidate question
query = cls.query(cls.answerer == None, cls.last_assigned < expiry)
# If a question has never been assigned, order by when it was asked
query = query.order(cls.last_assigned, cls.asked)
candidates = [candidate for candidate in query.fetch(2)
if candidate.asker != user]
if not candidates:
# No valid questions in queue.
break
# Try and assign it
question = cls._try_assign(candidates[0].key, user, expiry)
# Expire the assignment after a couple of minutes
return question
#ndb.transactional
def unassign(self, user):
"""Unassigns the given user from this question.
Args:
user: datastore_types.IM: The user who will no longer be answering
this question.
"""
question = self.key.get()
if user in question.assignees:
question.assignees.remove(user)
question.put()
#classmethod
def get_asked(cls, user):
"""Returns the user's outstanding asked question, if any.
Args:
user: datastore_types.IM: The identity of the user asking.
Returns:
An unanswered Question entity asked by the user, or None if there
are no unanswered questions.
"""
query = cls.query(cls.asker == user, cls.answer == None)
return query.get()
#classmethod
def get_answering(cls, user):
"""Returns the question the user is answering, if any.
Args:
user: datastore_types.IM: The identity of the user answering.
Returns:
An unanswered Question entity assigned to the user, or None if there
are no unanswered questions.
"""
query = cls.query(cls.assignees == user, cls.answer == None)
return query.get()
def bare_jid(sender):
"""Identify the user by bare jid.
See http://wiki.xmpp.org/web/Jabber_Resources for more details.
Args:
sender: String; A jabber or XMPP sender.
Returns:
The bare Jabber ID of the sender.
"""
return sender.split('/')[0]
class XmppHandler(xmpp_handlers.CommandHandler):
"""Handler class for all XMPP activity."""
def unhandled_command(self, message=None):
"""Shows help text for commands which have no handler.
Args:
message: xmpp.Message: The message that was sent by the user.
"""
message.reply(HELP_MSG.format(self.request.host_url))
def askme_command(self, message=None):
"""Responds to the /askme command.
Args:
message: xmpp.Message: The message that was sent by the user.
"""
im_from = datastore_types.IM('xmpp', bare_jid(message.sender))
currently_answering = Question.get_answering(im_from)
question = Question.assign_question(im_from)
if question:
message.reply(TELLME_MSG.format(question.question))
else:
message.reply(EMPTYQ_MSG)
# Don't unassign their current question until we've picked a new one.
if currently_answering:
currently_answering.unassign(im_from)
def text_message(self, message=None):
"""Called when a message not prefixed by a /cmd is sent to the XMPP bot.
Args:
message: xmpp.Message: The message that was sent by the user.
"""
im_from = datastore_types.IM('xmpp', bare_jid(message.sender))
question = Question.get_answering(im_from)
if question:
other_assignees = question.assignees
other_assignees.remove(im_from)
# Answering a question
question.answer = message.arg
question.answerer = im_from
question.assignees = []
question.answered = datetime.datetime.now()
question.put()
# Send the answer to the asker
xmpp.send_message([question.asker.address],
ANSWER_INTRO_MSG.format(question.question))
xmpp.send_message([question.asker.address],
ANSWER_MSG.format(message.arg))
# Send acknowledgement to the answerer
asked_question = Question.get_asked(im_from)
if asked_question:
message.reply(TELLME_THANKS_MSG)
else:
message.reply(THANKS_MSG)
# Tell any other assignees their help is no longer required
if other_assignees:
xmpp.send_message([user.address for user in other_assignees],
SOMEONE_ANSWERED_MSG)
else:
self.unhandled_command(message)
def tellme_command(self, message=None):
"""Handles /tellme requests, asking the Guru a question.
Args:
message: xmpp.Message: The message that was sent by the user.
"""
im_from = datastore_types.IM('xmpp', bare_jid(message.sender))
asked_question = Question.get_asked(im_from)
if asked_question:
# Already have a question
message.reply(WAIT_MSG)
else:
# Asking a question
asked_question = Question(question=message.arg, asker=im_from)
asked_question.put()
currently_answering = Question.get_answering(im_from)
if not currently_answering:
# Try and find one for them to answer
question = Question.assign_question(im_from)
if question:
message.reply(TELLME_MSG.format(question.question))
return
message.reply(PONDER_MSG)
class XmppPresenceHandler(webapp2.RequestHandler):
"""Handler class for XMPP status updates."""
def post(self, status):
"""POST handler for XMPP presence.
Args:
status: A string which will be either available or unavailable
and will indicate the status of the user.
"""
sender = self.request.get('from')
im_from = datastore_types.IM('xmpp', bare_jid(sender))
suspend = (status == 'unavailable')
query = Question.query(Question.asker == im_from,
Question.answer == None,
Question.suspended == (not suspend))
question = query.get()
if question:
question.suspended = suspend
question.put()
class LatestHandler(webapp2.RequestHandler):
"""Displays the most recently answered questions."""
#webapp2.cached_property
def jinja2(self):
"""Cached property holding a Jinja2 instance.
Returns:
A Jinja2 object for the current app.
"""
return jinja2.get_jinja2(app=self.app)
def render_response(self, template, **context):
"""Use Jinja2 instance to render template and write to output.
Args:
template: filename (relative to $PROJECT/templates) that we are
rendering.
context: keyword arguments corresponding to variables in template.
"""
rendered_value = self.jinja2.render_template(template, **context)
self.response.write(rendered_value)
def get(self):
"""Handler for latest questions page."""
query = Question.query(Question.answered > None).order(
-Question.answered)
self.render_response('latest.html', questions=query.fetch(20))
APPLICATION = webapp2.WSGIApplication([
('/', LatestHandler),
('/_ah/xmpp/message/chat/', XmppHandler),
('/_ah/xmpp/presence/(available|unavailable)/', XmppPresenceHandler),
], debug=True)
If a user selects another user whom he wants to chat with should call API url /_ah/xmpp/message/chat/ which automatically invokes XmppHandler handler.
('/_ah/xmpp/message/chat/', XmppHandler)
And my doubt is, If he post a message like foo on that particular chat does it automatically invokes text_message method exists in XmppHandler ? Is there we need to configure xmpp on client side also?
For the client api compatible and db migration, you can host your own parse-server.
There is a simple express project to use parse-server.
https://github.com/ParsePlatform/parse-server-example
They are lots of deploy guide to each cloud-platform
Google App Engine
Heroku and mLab
AWS and Elastic Beanstalk
Digital Ocean
NodeChef
Microsoft Azure
Pivotal Web Services
Back4app
Or you can host your nodejs server with your domain name.
If you want to do something different from parse, you can send a pull request to parse-server. LiveQuery is the extra function created by contributors.
For more details, see the link from Parse.com , github wiki, and community links.
Parse has provided detailed information regarding the migration
process and how to move our app from their serviers to a seperately
hosted mongoDB instance and cloud company. Parse suggests the
migration be made in two steps:
The database is migrated to a service like MongoLab or ObjectRocket.
The server be migrated to a cloud hosting company like AWS, Google App Engine, or Heroku.
Parse has also put suggested deadlines in place:
they suggest that by April 28, 2016 the database be migrated and by
July 28, 2016, the server be migrated properly.
This will give you ample time to work out any bugs and ensure your app functions properly with no downtime!
A Backend-as-a-Service like parse.com coupled two aspects of what’s known as a backend into one: the server and database. The server, which manipulates the database, performs queries, fetches information, and other work-intensive tasks, interacts with the database. The two work hand-in-hand to form a backend.
With Parse going away, we must deal with the server and database
seperately.
Parse has already provided detailed info and easy migration tool for database to Mongodb hosted on any cloud.
Also it is easy to setup the node based parse server on any cloud platform including Google App Engine:
The easiest way to get Parse server running on Google Cloud is to start with the sample out on GitHub.

Outlook - Read another user's calendar

I'm developing an Android App based on Outlook-SDK-Android. The App talks with Outlook Calendar REST API to retrieve, book and delete events (see code examples here and here). Now I need to read someone else's calendar and I've been provided an Office365 account with delegate access (author permission level) towards other users.
I've registered my app using the provided account on the new portal. In my App I use the scope "https://outlook.office.com/Calendars.ReadWrite".
(The scope is used in com.microsoft.aad.adal.AuthenticationContext.acquireToken() to initialize an Office REST Client for Android OutlookClient, a shared client stack provided by orc-for-android)
When I try to read another user's calendar on which I have delegate access I just receive back a 403 response:
{
"error": {
"code": "ErrorAccessDenied",
"message": "Access is denied. Check credentials and try again."
}
}
Any help?
Is it a limitation of the API? If so why is the following method invocation chain provided then?
outlookClient.getUsers()
.getById("meetingRoom#company.com")
.getCalendarView()
UPDATE:
It seems like there are works in progress that will allow this scenario, as reported here: Office 365 REST API - Access meeting rooms calendars
So if progress in that direction has been made can I achieve my goal without using an "admin service app"? (see Office 365 API or Azure AD Graph API - Get Someone Elses Calendar)
Can I use basic authentication as suggested here?
Calendar delegation is a feature of Exchange, the Graph API and Outlook API do not allow the user to access the delegated calendar.
Currently, the alternative workaround could be use the EWS. And here is an sample for your reference:
static void DelegateAccessSearchWithFilter(ExchangeService service, SearchFilter filter)
{
// Limit the result set to 10 items.
ItemView view = new ItemView(10);
view.PropertySet = new PropertySet(ItemSchema.Subject,
ItemSchema.DateTimeReceived,
EmailMessageSchema.IsRead);
// Item searches do not support deep traversal.
view.Traversal = ItemTraversal.Shallow;
// Define the sort order.
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
try
{
// Call FindItems to find matching calendar items.
// The FindItems parameters must denote the mailbox owner,
// mailbox, and Calendar folder.
// This method call results in a FindItem call to EWS.
FindItemsResults<Item> results = service.FindItems(
new FolderId(WellKnownFolderName.Calendar,
"fx#msdnofficedev.onmicrosoft.com"),
filter,
view);
foreach (Item item in results.Items)
{
Console.WriteLine("Subject: {0}", item.Subject);
Console.WriteLine("Id: {0}", item.Id.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine("Exception while enumerating results: { 0}", ex.Message);
}
}
private static void GetDeligateCalendar(string mailAddress, string password)
{
ExchangeService service = new ExchangeService();
service.Credentials = new WebCredentials(mailAddress, password);
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl(mailAddress, RedirectionUrlValidationCallback);
SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(AppointmentSchema.Subject, "Discuss the Calendar REST API"));
DelegateAccessSearchWithFilter(service, sf);
}
And if you want the Outlook and Graph API to support this feature, you can try to contact the Office developer team from link below:
https://officespdev.uservoice.com/
FindMeetingTimes is currently in preview! To view the details, use this link and then change it to view the Beta version of the article (top right in the main column): https://msdn.microsoft.com/en-us/office/office365/api/calendar-rest-operations#Findmeetingtimespreview
Details below from the article, but please use the link to get the latest:
Find meeting times (preview)
Find meeting time suggestions based on organizer and attendee availability, and time or location constraints.
This operation is currently in preview and available in only the beta version.
All the supported scenarios use the FindMeetingTimes action. FindMeetingTimes accepts constraints specified as parameters in the request body, and checks the free/busy status in the primary calendars of the organizer and attendees. The response includes meeting time suggestions, each of which is defined as a MeetingTimeCandidate, with attendees having on the average a confidence level of 50% chance or higher to attend.

How to parse the Json data when there are no nodes before JSONArray? (Android)

[
-{
body: "Deloitte experts believe that Expo 2020 Dubai will be a major “game changer for Dubai” whereby it will create significant changes — whether opportunities or challenges — in most industries and market sectors that could spill over to other countries in the region. “It is clear that Expo 2020 will go beyond a local showcase of commerce, technology and infrastructure, however impressive these things may be,” said Mutasem Dajani, Deloitte UAE regional managing partner. He adds: “Dubai will itself become an agent for future global progress as securing sustainable energy and resources, connecting and moving people, goods and services across markets and exploring the intrinsic spirit of entrepreneurship come together in a location that is uniquely synonymous with achievement in each of these areas.” Humphry Hatton, CEO of Deloitte Corporate Finance Limited (DCFL) regulated by the DIFC, addresses international investments in the region and adds that hosting Expo 2020 in Dubai will “further the attractiveness of Dubai as a base for overseas companies wishing to invest in the Middle East.” Anis Sadek, Dubai managing partner at Deloitte points out that, “It only takes a quick analysis of the impact of an expected additional 20 million international visitors over a six-month period to see that significant investment in hospitality and retail infrastructure will be required.” Rashid Bashir, head of the strategy practice at Deloitte Middle East cautions that “it would be beneficial to develop a dedicated legacy plan to ensure that the event’s potential as a catalyst to transform Dubai’s economy is maximized”. Their views are grouped in the report “Expo 2020: A game changer for Dubai”, and “Countdown to FATCA” available in the spring 2014 issue of the Deloitte Middle East Point of View (ME PoV) publication which also includes the views of other Deloitte partners and industry experts Cynthia Corby, Akbar Ahmad and Jesdev Saggar on the impact of Expo 2022 in the construction, financial services, and infrastructure and capital industries."
created_at: "2014-04-22T08:18:14Z"
date_time: "2014-04-22T08:18:14Z"
department: "Finance"
id: 291
include: true
mediaType: "Domestic Social Media"
priority: "1"
title: "Expo 2020 game will be changer for Dubai"
updated_at: "2014-04-22T08:18:34Z"
user_id: 2
},
-{
body: "Dubai: Dubai’s foreign trade is expected to touch Dh4 trillion by hosting Expo 2020, Mahmoud Al Bastaki, CEO of Dubai Trade, said on day two of the Annual Investment Meeting 2014 in Dubai. “While all business sectors will be growing drastically from now until the hosting of Expo 2020, trade will get the highest leap among all businesses in the UAE,” he said during plenary session at AIM entitle Expo 2020, unlocking new opportunities for potential partnerships in the UAE and the region. In 2013, Dubai trade hit Dh1.392 trillion and was the major contributors to Dubai’s GDP with almost 30 per cent of the total. Ahead of Expo 2020, the government will keep spending on infrastructure, prompting more businesses and investment will come to the UAE. New projects to be developed across all business sectors, and demand on goods will be drastically increase. All these factors will energise the trade market overall, Al Bastaki said. He also added that Expo 2020 will facilitate economic diversification by finding new paths for economic developments. “One of these paths is the development of the physical and social infrastructure, innovation centers and partnership projects.” In line with hosting this big event, the real estate market will witness great developments especially in the area around the Expo site and Dubai World Central. “This alone will boost most of the relevant sectors including wholesale trade, transport and logistics, communications and business services,” The development of other manufacturing industries, cement, construction materials will take part in this boost. Highlighting economic sectors growth and development prior Expo 2020 and how it will go during and after this event, Khalifa Al Zaffin, Executive Chairman of Dubai Aviation City Corporation, in line with Expo 2020 opportunities to capitalise on thriving sector. “In anticipation of the upcoming Expo, Dubai World Central (DWC) has witnessed an increase in land value and development activity which means a potential for attracting new investments,’ Al Zaffin said. “And over the coming years we expect to see a surge in both commercial and residential investments which definitely will be stimulating the small and medium enterprises (SMEs) as well as services sector,” he added. During Expo 2020, Al Zaffin portray how DWC will be a unique business and residential community district during expo. “DWC will include all facilities for businesses, residents and visitors. There will be districts for logistic, business, commercial, residential, exhibitions, hospitality, humanitarian and entertainment.” All these will be developed by attracted a lot of local and foreign investors, and will be resulting in natural growth of Gross Domestic Production (GDP) during and after Expo 2020, he added. Infrastructure UAE and Dubai is going to invest heavily on infrastructure ahead of Expo 2020, said Khalid Al Malek, CEO Group of Dubai Properties Group, during the plenary session. He also expected this to enhance growth in other relative sectors, including real estate and construction. According to the latest statistic last year, Al Malek said, construction and infrastructure projects announced and underway in the Gulf Cooperation Council (GCC) countries accounts for $1.9 trillion while UAE’s shares accounts for 49 per cent of the overall projects. “UAE continues to remain the largest projects market, with around $940 billion project that have been under execution,” he added. Projects in the UAE are dominated by infrastructure and construction, as several large projects that were earlier deferred or delayed have been revived, he said. Sizeable investment in utilities is taking place as well, given the ambitious long-term growth plans, according to him. Al Malek described the overall investment climate as a conducive with well established infrastructure and connectivity with the rest of the world. This is one of the advantage that Dubai enjoys to attract investments. Adding to this, he remarked that significant availability of low cost natural resources, consistent GDP growth and generation of surplus, high positioning in transparency and competitiveness index, re-export hub, developed free zones and strategic location are Dubai’s economic strength, Al Malek said."
created_at: "2014-04-15T10:19:07Z"
date_time: "2014-04-15T10:19:07Z"
department: "Finance"
id: 247
include: true
mediaType: "International Established"
priority: "1"
title: "Dubai Expo 2020 to produce Dh4 trillion foreign trade"
updated_at: "2014-04-15T10:19:16Z"
user_id: 2
}]
The above is my complete json data. I bought the json data successfully to my logcat by writing below code.
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("Accept", "application/json");
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
StatusLine statusLine = httpResponse.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode != 200) {
Toast.makeText(MainActivity.this, "error" + statusCode,
Toast.LENGTH_SHORT).show();
return null;
}
HttpEntity httpEntity = httpResponse.getEntity();
InputStream inputStream = httpEntity.getContent();
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(inputStream));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
String jsonData = stringBuilder.toString();
//To display json data in LOGCAT
Log.d("Latest 20 feeds", jsonData);
My question is how can i parse the data and display in logcat, ex: all the "title", "body" etc.
First thing first, you have invalid JSON data. I don't know how did you check and found that valid but I found a lot of errors and you can check that too by pasting it here JSON Validate
I have removed some of your STRING data to make it fit well in the space and removed errors, so how it looks like is here
[
{
"body": "Deloitte experts believe that Expo 2020 Dubai will and infrastructure and capital industries.",
"created_at": "2014-04-22T08:18:14Z",
"date_time": "2014-04-22T08:18:14Z",
"department": "Finance",
"id": 291,
"include": true,
"mediaType": "Domestic Social Media",
"priority": "1",
"title": "Expo 2020 game will be changer for Dubai",
"updated_at": "2014-04-22T08:18:34Z",
"user_id": 2
},
{
"body": "Dubai: Dubai’s foreign trade is expected to, Al Malek said.",
"created_at": "2014-04-15T10:19:07Z",
"date_time": "2014-04-15T10:19:07Z",
"department": "Finance",
"id": 247,
"include": true,
"mediaType": "International Established",
"priority": "1",
"title": "Dubai Expo 2020 to produce Dh4 trillion foreign trade",
"updated_at": "2014-04-15T10:19:16Z",
"user_id": 2
}
]
and it's in valid format now, so all you need now to do is...
JSONAarray array = new JSONArray(JsonString);
for(int i=0; i<array.length(); i++){
JSONObject object = array.getJSONObject(i);
String title = object.getString("title");
String body = object.getString("body");
System.out.println("Titlte: " + title);
System.out.println("Body: " + body);
}
Iterate JSON Dynamically this way
Create these Methods
1)
public void parseJson(JSONArray data) {
try {
JSONObject obj = new JSONObject();
obj.put("data", data);
parseJson(obj);
} catch (Exception e) {
e.printStackTrace();
}
}
2)
private void parseJson(JSONObject data) {
if (data != null) {
Iterator<String> it = data.keys();
while (it.hasNext()) {
String key = it.next();
try {
if (data.get(key) instanceof JSONArray) {
JSONArray arry = data.getJSONArray(key);
int size = arry.length();
for (int i = 0; i < size; i++) {
parseJson(arry.getJSONObject(i));
}
} else if (data.get(key) instanceof JSONObject) {
parseJson(data.getJSONObject(key));
} else {
System.out.println(key + " : " + data.getString(key));
}
} catch (Throwable e) {
try {
System.out.println(key + " : " + data.getString(key));
} catch (Exception ee) {
}
e.printStackTrace();
}
}
}
}
How to Use?
String jsonData = stringBuilder.toString();
try {
parseJson(new JSONArray(jsonData));
} catch (Exception e) {
}
In your example JSONArray. So you can parse it to Array of objects. Simple way is using Gson:
String jsonData = stringBuilder.toString();
Gson gson = new Gson();
MyDataObject [] data = gson.fromJson(jsonData, MyDataObject[].class);
Use Google GSON lib for auto parsing (just download latest version of GSON jar file and put it to your project inside libs folder):
1) Create class describing your data model
public class SomeObjectClass {
#SerializedName("body")
private String mBody;
#SerializedName("created_at")
private String mCreatedAt;
#SerializedName("date_time")
private String mDateTime;
#SerializedName("department")
private String mDepartment;
#SerializedName("id")
private long mId;
#SerializedName("include")
private boolean mInclude;
// another fields here
// some getters if you need it
}
2) Create method for parsing your json string to list of your objects
public List<SomeObjectClass> parseJson(String jsonArray) {
Type listType = new TypeToken<ArrayList<SomeObjectClass>>() {}.getType();
List<SomeObjectClass> yourClassList = new Gson().fromJson(jsonArray, listType);
return yourClassList;
}
3) Parse your json
List<SomeObjectClass> objects = parseJson(jsonData);
4) Iterate it and log
I would make sure that the json string you get is valid. When it a valid JSON, by using the JSONArray constructor provided with the jsonData string you would get a JSONArray of your json objects. here is a full example:
jsonData = "{" + jsonData + "}";
JSONArray json = new JSONArray(jsonData);
I hope you are using this JSON library.
From my investigation it is not valid (missing semi columns and more). You can use this tool to validate your json.
Here is a valid json string:
[
{
"body": "Deloitte experts believe that Expo 2020 Dubai will be a major “game changer for Dubai” whereby it will create significant changes — whether opportunities or challenges — in most industries and market sectors that could spill over to other countries in the region. “It is clear that Expo 2020 will go beyond a local showcase of commerce, technology and infrastructure, however impressive these things may be,” said Mutasem Dajani, Deloitte UAE regional managing partner. He adds: “Dubai will itself become an agent for future global progress as securing sustainable energy and resources, connecting and moving people, goods and services across markets and exploring the intrinsic spirit of entrepreneurship come together in a location that is uniquely synonymous with achievement in each of these areas.” Humphry Hatton, CEO of Deloitte Corporate Finance Limited (DCFL) regulated by the DIFC, addresses international investments in the region and adds that hosting Expo 2020 in Dubai will “further the attractiveness of Dubai as a base for overseas companies wishing to invest in the Middle East.” Anis Sadek, Dubai managing partner at Deloitte points out that, “It only takes a quick analysis of the impact of an expected additional 20 million international visitors over a six-month period to see that significant investment in hospitality and retail infrastructure will be required.” Rashid Bashir, head of the strategy practice at Deloitte Middle East cautions that “it would be beneficial to develop a dedicated legacy plan to ensure that the event’s potential as a catalyst to transform Dubai’s economy is maximized”. Their views are grouped in the report “Expo 2020: A game changer for Dubai”, and “Countdown to FATCA” available in the spring 2014 issue of the Deloitte Middle East Point of View (ME PoV) publication which also includes the views of other Deloitte partners and industry experts Cynthia Corby, Akbar Ahmad and Jesdev Saggar on the impact of Expo 2022 in the construction, financial services, and infrastructure and capital industries.",
"created_at": "2014-04-22T08:18:14Z",
"date_time": "2014-04-22T08:18:14Z",
"department": "Finance",
"id": 291,
"include": true,
"mediaType": "Domestic Social Media",
"priority": 1,
"title": "Expo 2020 game will be changer for Dubai",
"updated_at": "2014-04-22T08:18:34Z",
"user_id": 2
},
{
"body": "Dubai: Dubai’s foreign trade is expected to touch Dh4 trillion by hosting Expo 2020, Mahmoud Al Bastaki, CEO of Dubai Trade, said on day two of the Annual Investment Meeting 2014 in Dubai. “While all business sectors will be growing drastically from now until the hosting of Expo 2020, trade will get the highest leap among all businesses in the UAE,” he said during plenary session at AIM entitle Expo 2020, unlocking new opportunities for potential partnerships in the UAE and the region. In 2013, Dubai trade hit Dh1.392 trillion and was the major contributors to Dubai’s GDP with almost 30 per cent of the total. Ahead of Expo 2020, the government will keep spending on infrastructure, prompting more businesses and investment will come to the UAE. New projects to be developed across all business sectors, and demand on goods will be drastically increase. All these factors will energise the trade market overall, Al Bastaki said. He also added that Expo 2020 will facilitate economic diversification by finding new paths for economic developments. “One of these paths is the development of the physical and social infrastructure, innovation centers and partnership projects.” In line with hosting this big event, the real estate market will witness great developments especially in the area around the Expo site and Dubai World Central. “This alone will boost most of the relevant sectors including wholesale trade, transport and logistics, communications and business services,” The development of other manufacturing industries, cement, construction materials will take part in this boost. Highlighting economic sectors growth and development prior Expo 2020 and how it will go during and after this event, Khalifa Al Zaffin, Executive Chairman of Dubai Aviation City Corporation, in line with Expo 2020 opportunities to capitalise on thriving sector. “In anticipation of the upcoming Expo, Dubai World Central (DWC) has witnessed an increase in land value and development activity which means a potential for attracting new investments,’ Al Zaffin said. “And over the coming years we expect to see a surge in both commercial and residential investments which definitely will be stimulating the small and medium enterprises (SMEs) as well as services sector,” he added. During Expo 2020, Al Zaffin portray how DWC will be a unique business and residential community district during expo. “DWC will include all facilities for businesses, residents and visitors. There will be districts for logistic, business, commercial, residential, exhibitions, hospitality, humanitarian and entertainment.” All these will be developed by attracted a lot of local and foreign investors, and will be resulting in natural growth of Gross Domestic Production (GDP) during and after Expo 2020, he added. Infrastructure UAE and Dubai is going to invest heavily on infrastructure ahead of Expo 2020, said Khalid Al Malek, CEO Group of Dubai Properties Group, during the plenary session. He also expected this to enhance growth in other relative sectors, including real estate and construction. According to the latest statistic last year, Al Malek said, construction and infrastructure projects announced and underway in the Gulf Cooperation Council (GCC) countries accounts for $1.9 trillion while UAE’s shares accounts for 49 per cent of the overall projects. “UAE continues to remain the largest projects market, with around $940 billion project that have been under execution,” he added. Projects in the UAE are dominated by infrastructure and construction, as several large projects that were earlier deferred or delayed have been revived, he said. Sizeable investment in utilities is taking place as well, given the ambitious long-term growth plans, according to him. Al Malek described the overall investment climate as a conducive with well established infrastructure and connectivity with the rest of the world. This is one of the advantage that Dubai enjoys to attract investments. Adding to this, he remarked that significant availability of low cost natural resources, consistent GDP growth and generation of surplus, high positioning in transparency and competitiveness index, re-export hub, developed free zones and strategic location are Dubai’s economic strength, Al Malek said.",
"created_at": "2014-04-15T10: 19: 07Z",
"date_time": "2014-04-15T10: 19: 07Z",
"department": "Finance",
"id": 247,
"include": true,
"mediaType": "InternationalEstablished",
"priority": 1,
"title": "DubaiExpo2020toproduceDh4trillionforeigntrade",
"updated_at": "2014-04-15T10: 19: 16Z",
"user_id": 2
}
]

Propper way to handle dumping and reloading of JSON data containing special characters on android?

Not sure if this has been answered already but a quick search didn't turn up a satisfying result..
I'm stuck with the following scenario:
web service with REST API and JSON formatted data blobs
android client app talking to this service and locally caching / processing the data
The we service is run by a German company so some of the strings in the result data contain special characters like German umlauts:
// example resonse
[
{
"title" : "reward 1",
"description" : "Ein gro\u00dfer Kaffee f\u00fcr dich!"
},
{
"title" : "reward 2",
"description" : "Eine Pizza f\u00fcr dich!"
},
...
]
Locally the app is parsing the data using a set of classes which mirror the response objects (e.g. Reward and RewardResponse classes for the upper example). Each of these classes can read and dump itself from / to JSON - however this is where things get ugly.
Taking the example above org.json will correctly parse the data and the resulting strings will contain proper Unicode versions of the special characters 'ß' (\u00df) and 'ü' (\u00fc).
final RewardResponse response = new RewardResponse(jsonData);
final Reward reward = response.get(0);
// this will print "Ein großer Kaffee für dich!"
Log.d("dump server data", reward.getDescription());
final Reward reward2 = new Reward(reward.toJSON());
// this will print "Ein gro�er Kaffee f�r dich!"
Log.d("dump reloaded data", reward2.getDescription());
As you can see there is a problem with loading the data generated by JSONObject.toString().
Mainly whats happening is that JSONObject will parse escapes in the form of "\uXXXX" but it will dump them as plain UTF-8 text.
In turn, when parsing it won't properly read the unicode and instead insert a replacement character in the result string (� above \uffff as code point).
My current workaround consists of a look-up table containing the Unicode Latin1 supplement characters and their respective escaped versions (\u00a0 up to \u00ff). But this also means I have to go over each and every dumped JSON text and replace the characters with their escaped versions each time I dump something.
Please tell me there is a better way for this!
(Note: there is this question however he had problems with local file encoding on disk.
My problem above, as you can see, is reproducible without ever writing to disk)
EDIT: As requested in the comments here's the toJSON() method:
public final String toJSON() {
JSONObject obj = new JSONObject();
// mTitle and mDescription contain the unmodified
// strings received from parsing.
obj.put("title", mTitle);
obj.put("description", mDescription);
return obj.toString();
}
As a side note it makes no difference if I use JSONObject.toString() or a JSONStringer.
(The documentation advises to use .toString())
EDIT: just to remove Reward from the equation, this reproduces the problem:
final JSONObject inputData = new JSONObject("{\"description\":\"Ein gro\\u00dfer Kaffee\"}");
final JSONObject parsedData = new JSONObject(inputData.toString());
Log.d("inputData", inputData.getString("description"));
Log.d("parsedData", parsedData.getString("description"));
[Note: posted as an answer for better formatting]
I just tried the example
final JSONObject inputData = new JSONObject("{\"description\":\"Ein gro\\u00dfer Kaffee\"}");
final JSONObject parsedData = new JSONObject(inputData.toString());
Log.d("inputData", inputData.getString("description"));
Log.d("parsedData", parsedData.getString("description"));
on my Nexus 7 running Android 4.2.1, and on Nexus S running 4.1.2, and it works as intended:
D/inputData(17281): Ein großer Kaffee
D/parsedData(17281): Ein großer Kaffee
In which Android version did you see the problem?

Categories

Resources