Json格式结果 - 仅显示具有结果集的特定字段 [英] Json format result - only specific field display with result set

查看:71
本文介绍了Json格式结果 - 仅显示具有结果集的特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用google api在附近搜索



https://maps.googleapis.com/maps/api/place/textsearch/xml?query=restaurants + in + Sydney& key = YOUR_API_KEY





我只想要json格式的结果附近信息。



请告知我如何过滤结果并仅显示json格式的附近(地址)信息。







String sURL =https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=;

sURL + = objNearByServicesRequest .Latitude +,+ objNearByServicesRequest.Longitude;

sURL + =& radius =+ WebConfigurationManager.AppSettings [RadiusNearBySearch] +& types =+ objNearByServicesRequest.Types + & keyword =+ objNearByServicesRequest.Keyword;

sURL + =& key =+ WebConfigurationManager.AppSettings [GoogleAPIKeyNearBySearch];



String strreturn = String.Empty;





使用(var client = new WebClient())

使用(var stream = client.OpenRead(sURL))

using(var reader =新的StreamReader(流))

{

var jObject = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadToEnd());

Console.WriteLine((string)jObject [results] [0] [nearby]);

}





我想以json格式显示2个字段,如下所示。

如何使用C#编写以下格式显示的代码。



[

{

id:1,

附近:Opp。火车站,Gabba Estate,Gohar Baug,孟买,



},

{

id :2

附近:SH 15,Navjivan Colony,Mumbai,



}



]



我尝试过:



如何使用C#编写以下格式显示的代码。



[

{

id:1,

附近:Opp。火车站,Gabba Estate,Gohar Baug,孟买,



},

{

id :2

附近:SH 15,Navjivan Colony,Mumbai,



}



]

I search near by palce using google api

https://maps.googleapis.com/maps/api/place/textsearch/xml?query=restaurants+in+Sydney&key=YOUR_API_KEY


I want only vicinity information from result in json format.

Please advise how can I filter result and display only vicinity(address) information in json format.



String sURL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=";
sURL += objNearByServicesRequest.Latitude + "," + objNearByServicesRequest.Longitude;
sURL += "&radius=" + WebConfigurationManager.AppSettings["RadiusNearBySearch"] + "&types=" + objNearByServicesRequest.Types + "&keyword=" + objNearByServicesRequest.Keyword;
sURL += "&key=" + WebConfigurationManager.AppSettings["GoogleAPIKeyNearBySearch"];

String strreturn = String.Empty;


using (var client = new WebClient())
using (var stream = client.OpenRead(sURL))
using (var reader = new StreamReader(stream))
{
var jObject = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadToEnd());
Console.WriteLine((string)jObject["results"][0]["vicinity"]);
}


I want to display out out in json format for 2 field like below.
how can I write code for display out put in below format using C#.

[
{
"id": 1,
"vicinity": "Opp. Railway Station, Gabba Estate,, Gohar Baug, Mumbai",

},
{
"id": 2
"vicinity": "SH 15, Navjivan Colony, Mumbai",

}

]

What I have tried:

how can I write code for display out put in below format using C#.

[
{
"id": 1,
"vicinity": "Opp. Railway Station, Gabba Estate,, Gohar Baug, Mumbai",

},
{
"id": 2
"vicinity": "SH 15, Navjivan Colony, Mumbai",

}

]

推荐答案

您已经在使用Google API进行地点搜索 [ ^ ],并收到一些建议。
You already posted this question at Near by place search using Google api[^], and received some suggestions.


这篇关于Json格式结果 - 仅显示具有结果集的特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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