从GOOGLE API返回的JSON中获取数据 [英] Get data from JSON which is returned from GOOGLE API

查看:126
本文介绍了从GOOGLE API返回的JSON中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我正在开发一个应用程序,其要求就像根据用户的国家/地区选择国家/地区下拉列表一样。



例如:如果我的申请用户来自新加坡,那么应该在下拉菜单中选择新加坡,如果来自印度,则应选择印度。



要做到这一点,我使用的是Google API, Google API [ ^ ],它返回一个JSON对象。现在我想从这个JSON对象中仅获取国家名称。



我保持断点并且能够在浏览器中看到返回的JSON对象。但是如何从这里获得国家名称?



任何建议朋友......?

Hi Friends,

I'm developing a application in that the requirements are like making the country drop down list selected based on the user's country.

For ex: If the user of my application is from Singapore then singapore should be selected in the drop down and if from India , then India should be selected.

To do this I'm using Google API, Google API[^], and it is returning a JSON object. Now I want to fetch only country name from this JSON object.

I kept break point and able to see the returned JSON object in browser. But how to get the Country name from this?

Any suggestions friends...?

推荐答案

您好Tejas,



您现在的位置:



添加对Newtonsoft.Json的引用;

Hi Tejas,

Here you go:

Add reference to Newtonsoft.Json;
using Newtonsoft.Json;





这里获取国家代码:





Here the code to get Country:

WebClient wc = new WebClient(); // here I'm using Web Client to get the JSON data frm GMaps API for demo., you're free to use of your choice.

var jsonStr = wc.DownloadString("http://maps.googleapis.com/maps/api/geocode/json?latlng=17.37528,78.47444&sensor=false");
           JObject a = JObject.Parse(jsonStr);
           var addresses = a["results"][0]["formatted_address"].ToString();
           var country = addresses.Split(',')[(addresses.Split(',').Length - 1)].Trim();







希望它有所帮助。



快乐编码:)




Hope it helps.

Happy Coding :)


查看此链接。您将了解如何从中获取数据。



Deserialize Json [ ^ ]



问候..
See this link. You will get an idea regarding how to get data out of it.

Deserialize Json[^]

Regards..


这篇关于从GOOGLE API返回的JSON中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆