【问题标题】:Titanium - Json Object Returning an empty arrayTitanium - Json 对象返回一个空数组
【发布时间】:2014-12-24 12:05:04
【问题描述】:

我的 WEC 网络服务返回一个 JSON 对象,我想在我的 Titanium 应用程序中使用它,但问题是,JSON 对象中有数组,我可以在控制台中看到它们,但是当我尝试通过提供访问时索引,它不起作用。

示例

{
    "GetDoctorFavoriteTestResult": "{\"CountryList\":null,\"AddressDetails\":null,\"CollectionAddressDetails\":null,\"CourierAddressDetails\":null,\"labAddressDetails\":null,\"TestDetails\":[{\"TestID\":29,\"TestName\":\"CEA-Carcino Embryonic Antigen, serum\",\"Row\":0,\"LabID\":0,\"DoctorPatientMappingId\":0,\"PatientId\":0,\"TestDesc\":\"Colonic cancer marker.\\n\\nNote\\n1. This test is not recommended for cancer screening in the general population.\\n2. False negative / positive results are observed in patients receiving mouse monoclonal antibodies for diagnosis or therapy.\\n3. Patients with confirmed carcinoma may show normal pre-treatment CEA levels. Hence this assay, regardless of level, should not be interpreted as absolute evidence for presence or absence of malignant disease. The assay value should be used in conjunction with fi\",\"TestPrice\":0.0,\"BasePrice\":0.0,\"DiscountPrice\":0.0,\"Currency\":null,\"SampleAtHome\":false,\"IsActive\":false,\"LabName\":null,\"TestPerformedLabName\":null,\"Link\":null,\"TestResult\":null,\"UploadedTestFile\":null,\"PatientName\":null,\"TestRemarks\":null,\"ResultType\":null,\"TestFavouriteId\":0,\"CollectionPrice\":0.0,\"TotalPrice\":0.0,\"PaymentToECL\":0.0,\"PaymentFromECL\":0.0,\"ToBeListed\":true,\"OrderAmt\":0.0,\"AfterDiscountPrice\":0.0,\"CollectionType\":0,\"PreferedDate\":\"0001-01-01T00:00:00\",\"PreferedTime\":null,\"SpecialInstructions\":null,\"PaymentType\":0,\"PaymentTypeStatus\":null,\"PaymentStatus\":null,\"CourierAddressId\":0,\"CollectionAddressId\":0,\"OrderId\":0,\"OrderDetailId\":0,\"BookedDateTime\":\"0001-01-01T00:00:00\",\"ModifiedDate\":\"0001-01-01T00:00:00\",\"PreviousSlotDateTime\":null,\"CategoryID\":0,\"TestCode\":null,\"CPTCode\":null,\"Abbrevation\":\"CEA\",\"MethodID\":0,\"SampleTypeID\":0,\"SampleTypeDesc\":null,\"TempId\":0,\"Description\":null,\"TAT\":null,\"TestType\":0,\"SampleOptions\":null,\"IdCountry\":0,\"IdState\":0,\"IdCity\":0,\"MethodName\":null,\"CategoryName\":null,\"TestCondition\":null,\"HyperLink\":null,\"ReferenceValue\":null,\"Units\":null,\"ReportAttributes\":null,\"OrderStatus\":null,\"TestAvailableHome\":false,\"PathologistId\":0,\"PathologistName\":null,\"TechnicianName\":null,\"PathologistSign\":null,\"TechnicianSing\":null,\"EmailId\":null,\"LabEmailId\":null,\"SampleCollectedDate\":null,\"ReportUploadedDate\":null,\"IsExists\":false},{\"TestID\":73,\"TestName\":\"Family Finder + Y-DNA67\",\"Row\":0,\"LabID\":0,\"DoctorPatientMappingId\":0,\"PatientId\":0,\"TestDesc\":\"Family Finder + Y-DNA67\",\"TestPrice\":0.0,\"BasePrice\":0.0,\"DiscountPrice\":0.0,\"Currency\":null,\"SampleAtHome\":false,\"IsActive\":false,\"LabName\":null,\"TestPerformedLabName\":null,\"Link\":null,\"TestResult\":null,\"UploadedTestFile\":null,\"PatientName\":null,\"TestRemarks\":null,\"ResultType\":null,\"TestFavouriteId\":0,\"CollectionPrice\":0.0,\"TotalPrice\":0.0,\"PaymentToECL\":0.0,\"PaymentFromECL\":0.0,\"ToBeListed\":true,\"OrderAmt\":0.0,\"AfterDiscountPrice\":0.0,\"CollectionType\":0,\"PreferedDate\":\"0001-01-01T00:00:00\",\"PreferedTime\":null,\"SpecialInstructions\":null,\"PaymentType\":0,\"PaymentTypeStatus\":null,\"PaymentStatus\":null,\"CourierAddressId\":0,\"CollectionAddressId\":0,\"OrderId\":0,\"OrderDetailId\":0,\"BookedDateTime\":\"0001-01-01T00:00:00\",\"ModifiedDate\":\"0001-01-01T00:00:00\",\"PreviousSlotDateTime\":null,\"CategoryID\":0,\"TestCode\":null,\"CPTCode\":null,\"Abbrevation\":\"Family Finder + Y-DNA67\",\"MethodID\":0,\"SampleTypeID\":0,\"SampleTypeDesc\":null,\"TempId\":0,\"Description\":null,\"TAT\":null,\"TestType\":0,\"SampleOptions\":null,\"IdCountry\":0,\"IdState\":0,\"IdCity\":0,\"MethodName\":null,\"CategoryName\":null,\"TestCondition\":null,\"HyperLink\":null,\"ReferenceValue\":null,\"Units\":null,\"ReportAttributes\":null,\"OrderStatus\":null,\"TestAvailableHome\":false,\"PathologistId\":0,\"PathologistName\":null,\"TechnicianName\":null,\"PathologistSign\":null,\"TechnicianSing\":null,\"EmailId\":null,\"LabEmailId\":null,\"SampleCollectedDate\":null,\"ReportUploadedDate\":null,\"IsExists\":false},{\"TestID\":69,\"TestName\":\"Family Finder (For Both)\",\"Row\":0,\"LabID\":0,\"DoctorPatientMappingId\":0,\"PatientId\":0,\"TestDesc\":\"Family Finder (For Both)\",\"TestPrice\":0.0,\"BasePrice\":0.0,\"DiscountPrice\":0.0,\"Currency\":null,\"SampleAtHome\":false,\"IsActive\":false,\"LabName\":null,\"TestPerformedLabName\":null,\"Link\":null,\"TestResult\":null,\"UploadedTestFile\":null,\"PatientName\":null,\"TestRemarks\":null,\"ResultType\":null,\"TestFavouriteId\":0,\"CollectionPrice\":0.0,\"TotalPrice\":0.0,\"PaymentToECL\":0.0,\"PaymentFromECL\":0.0,\"ToBeListed\":true,\"OrderAmt\":0.0,\"AfterDiscountPrice\":0.0,\"CollectionType\":0,\"PreferedDate\":\"0001-01-01T00:00:00\",\"PreferedTime\":null,\"SpecialInstructions\":null,\"PaymentType\":0,\"PaymentTypeStatus\":null,\"PaymentStatus\":null,\"CourierAddressId\":0,\"CollectionAddressId\":0,\"OrderId\":0,\"OrderDetailId\":0,\"BookedDateTime\":\"0001-01-01T00:00:00\",\"ModifiedDate\":\"0001-01-01T00:00:00\",\"PreviousSlotDateTime\":null,\"CategoryID\":0,\"TestCode\":null,\"CPTCode\":null,\"Abbrevation\":\"Family Finder (For Both)\",\"MethodID\":0,\"SampleTypeID\":0,\"SampleTypeDesc\":null,\"TempId\":0,\"Description\":null,\"TAT\":null,\"TestType\":0,\"SampleOptions\":null,\"IdCountry\":0,\"IdState\":0,\"IdCity\":0,\"MethodName\":null,\"CategoryName\":null,\"TestCondition\":null,\"HyperLink\":null,\"ReferenceValue\":null,\"Units\":null,\"ReportAttributes\":null,\"OrderStatus\":null,\"TestAvailableHome\":false,\"PathologistId\":0,\"PathologistName\":null,\"TechnicianName\":null,\"PathologistSign\":null,\"TechnicianSing\":null,\"EmailId\":null,\"LabEmailId\":null,\"SampleCollectedDate\":null,\"ReportUploadedDate\":null,\"IsExists\":false}],\"ExistingMappedTest\":null,\"AllTestDetails\":null,\"CountryPrices\":null,\"PriceComponents\":null,\"OrderedTestDetails\":null,\"BookedSlots\":null,\"LabScheduleDetails\":null,\"ReturnValue\":0,\"ReturnMessage\":null,\"TotalRecords\":0,\"Rows\":0,\"IsActive\":false}"
}

在这里,我可以使用 JSON.parse 访问 GetDoctorFavoriteTestResult.CountryList,但是当我尝试获取数组时 GetDoctorFavoriteTestResult.TestDetails它显示为空。

即使在浏览器中,Web 服务也能完美运行。

再次,我可以在 Titanium 控制台窗口中看到数组数据。

有什么办法吗?

【问题讨论】:

  • 你在 PC 或 mac 上安装了 chrome 吗?
  • PC,暂时为安卓工作。
  • 铬?我说的是钛,是的,我在 chrome 和 firefox 中测试了该服务,但数据相同。
  • 我有 chrome,现在该怎么办?
  • 你能把GetDoctorFavoriteTestResult.TestDetails周围的代码展示一下吗

标签: javascript json titanium


【解决方案1】:

安装此 chrome 扩展程序。它会自动为您提供 Titan 应用程序的路径

https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc?hl=en

谢谢

【讨论】:

  • { hey: "guy", anumber: 243, anobject: { whoa: "nuts", anarray: [], more: "stuff" }, awesome: true, bogus: false, 含义: null, link: "jsonview.com", notLink: "jsonview.com is great" } 我通过使用 chrome 的扩展得到了这个
  • 是的,您的 json 数据现在没有格式化并为您提供路径吗?
  • 从哪里可以得到路径?扩展中没有任何路径
  • 很抱歉打扰你 :D 我的这个扩展不能正常工作,让我先解决这个问题
  • 它不工作,我在两台机器上试过,扩展名没有出现。
【解决方案2】:

会更容易看到你是如何解析 json 的

试试这个: GetDoctorFavoriteTestResult[0].TestDetails

【讨论】:

猜你喜欢
  • 2011-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-10
  • 2015-11-10
  • 1970-01-01
  • 2020-03-23
相关资源
最近更新 更多