0
我喜歡使用rest api爲Eureka註冊服務編寫一個.net連接器。它要求如下所示的json格式,並希望從配置類中生成該json。找不到像「securePort」這樣的json在beginnnig中看起來像$和@這樣的屬性的某些屬性:{「$」:「8443」,「@enabled」:「true」},c#json使用屬性序列化
需要尤里卡JSON:
{
"instance": {
"hostName": "WKS-SOF-L011",
"app": "com.automationrhapsody.eureka.app",
"vipAddress": "com.automationrhapsody.eureka.app",
"secureVipAddress": "com.automationrhapsody.eureka.app"
"ipAddr": "10.0.0.10",
"status": "STARTING",
"port": {"$": "8080", "@enabled": "true"},
"securePort": {"$": "8443", "@enabled": "true"},
"healthCheckUrl": "http://WKS-SOF-L011:8080/healthcheck",
"statusPageUrl": "http://WKS-SOF-L011:8080/status",
"homePageUrl": "http://WKS-SOF-L011:8080",
"dataCenterInfo": {
"@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
"name": "MyOwn"
},
}
}
我的課,多數民衆贊成預期生成序列後下方的JSON(我用newtonsoft.json):
public class Port
{
public string PortName { get; set; }
[JsonProperty("enabled")]
public bool Enabled { get; set; }
}
public class DataCenterInfo
{
[JsonProperty("class")]
public string Class { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
public class EurekaRegisterParams
{
[JsonProperty("instanceId")]
public string InstanceId { get; set; }
[JsonProperty("hostName")]
public string HostName { get; set; }
[JsonProperty("app")]
public string App { get; set; }
[JsonProperty("ipAddr")]
public string IpAddr { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("port")]
public Port Port { get; set; }
[JsonProperty("securePort")]
public Port SecurePort { get; set; }
[JsonProperty("countryId")]
public string CountryId { get; set; }
[JsonProperty("dataCenterInfo")]
public DataCenterInfo DataCenterInfo { get; set; }
[JsonProperty("homePageUrl")]
public string HomePageUrl { get; set; }
[JsonProperty("statusPageUrl")]
public string StatusPageUrl { get; set; }
[JsonProperty("healthCheckUrl")]
public string HealthCheckUrl { get; set; }
}
在'Port'實體中向'PortName'屬性中添加'[JsonProperty(「$」)]''後,你嘗試過嗎? – Venky