2016-06-20 7 views
0
$http({ 
    method: 'GET', 
    // url: "https://na30.salesforce.com/services/data/v36.0/query?q=SELECT+id,+name,+Product2.Name,+Product2.Description,+Product2Id,+Pricebook2Id,+Product2.Family,+Product2.Product_Image_URL__c,+Product2.Product_Image__c,+Pricebook2.name+from+PricebookEntry+where+(Pricebook2.Id+=+'01s360000049JQh'+and+Product2.Family+=+'CURRIES')", 
    url: $scope.finalurl, 
    headers: { 'Content-Type': 'application/json' , 
        'Authorization' : $scope.result1 } 
    }).success(function(response) { 
    $scope.result= response.totalSize; 
// $scope.size = response. 
// alert(" Products records captured"); 
// alert($scope.result); 
    var y =response.records; 
    alert(y); 
    localStorage.setItem("offlinecurries1",JSON.stringify(y)); 
    var x =localStorage.getItem("offlinecurries1"); 
    alert(JSON.stringify(x[0].Name)); 

へのアクセス中にいる間は未定義のエラー上記のアラートに未定義のエラーを取得してJSONデータ

私の応答データは、この行は、文字列を返す

{ 
    "totalSize": 497, 
    "done": true, 
    "records": [{ 
     "attributes": { 
      "type": "PricebookEntry", 
      "url": "/services/data/v36.0/sobjects/PricebookEntry/01u36000001de83AAA" 
     }, 
     "Id": "01u36000001de83AAA", 
     "Name": "P-0025", 
     "Pricebook2Id": "01s36000004AGVLAA4", 
     "Product2": { 
      "attributes": { 
       "type": "Product2", 
       "url": "/services/data/v36.0/sobjects/Product2/01t36000001To1lAAC" 
      }, 
      "Product_Image_URL__c": null, 
      "Description": "ACHAPPAM175GMS X12PKT", 
      "Family": null, 
      "Product_Image__c": "<img src=\" \" alt=\"Not Avaialble\" height=\"50\" width=\"50\" border=\"0\"/>" 
     }, 
     "Product2Id": "01t36000001To1lAAC", 
     "Pricebook2": { 
      "attributes": { 
       "type": "Pricebook2", 
       "url": "/services/data/v36.0/sobjects/Pricebook2/01s36000004AGVLAA4" 
      }, 
      "Name": "UK Pricebook" 
     } 
    }, { 
     "attributes": { 
      "type": "PricebookEntry", 
      "url": "/services/data/v36.0/sobjects/PricebookEntry/01u36000001de84AAA" 
     }, 
     "Id": "01u36000001de84AAA", 
     "Name": "P-0026", 
     "Pricebook2Id": "01s36000004AGVLAA4", 
     "Product2": { 
      "attributes": { 
       "type": "Product2", 
       "url": "/services/data/v36.0/sobjects/Product2/01t36000001To1mAAC" 
      }, 
      "Product_Image_URL__c": null, 
      "Description": "ADA RICE 200 x 30", 
      "Family": null, 
      "Product_Image__c": "<img src=\" \" alt=\"Not Avaialble\" height=\"50\" width=\"50\" border=\"0\"/>" 
     }, 
     "Product2Id": "01t36000001To1mAAC", 
     "Pricebook2": { 
      "attributes": { 
       "type": "Pricebook2", 
       "url": "/services/data/v36.0/sobjects/Pricebook2/01s36000004AGVLAA4" 
      }, 
      "Name": "UK Pricebook" 
     } 
    }] 
} 

答えて

0
var x =localStorage.getItem("offlinecurries1"); 

です!あなたは右

var x =localStorage.getItem("offlinecurries1"); 
x = JSON.parse(x) 
+0

ありがとうございました。 –

0

後にこの行を追加し、JSONオブジェクトに文字列を解析する必要が

はこれを試してみてください。保存するときにstrigifyにする必要があります。検索中にJSON.parseを使用しているparseのjsonが必要なので、配列に変換することができます。

var json = { "totalSize": 497, "done": true, "records": [{ "attributes": { "type": "PricebookEntry", "url": "/services/data/v36.0/sobjects/PricebookEntry/01u36000001de83AAA" }, "Id": "01u36000001de83AAA", "Name": "P-0025", "Pricebook2Id": "01s36000004AGVLAA4", "Product2": { "attributes": { "type": "Product2", "url": "/services/data/v36.0/sobjects/Product2/01t36000001To1lAAC" }, "Product_Image_URL__c": null, "Description": "ACHAPPAM175GMS X12PKT", "Family": null, "Product_Image__c": "" }, "Product2Id": "01t36000001To1lAAC", "Pricebook2": { "attributes": { "type": "Pricebook2", "url": "/services/data/v36.0/sobjects/Pricebook2/01s36000004AGVLAA4" }, "Name": "UK Pricebook" } }, { "attributes": { "type": "PricebookEntry", "url": "/services/data/v36.0/sobjects/PricebookEntry/01u36000001de84AAA" }, "Id": "01u36000001de84AAA", "Name": "P-0026", "Pricebook2Id": "01s36000004AGVLAA4", "Product2": { "attributes": { "type": "Product2", "url": "/services/data/v36.0/sobjects/Product2/01t36000001To1mAAC" }, "Product_Image_URL__c": null, "Description": "ADA RICE 200 x 30", "Family": null, "Product_Image__c": "" }, "Product2Id": "01t36000001To1mAAC", "Pricebook2": { "attributes": { "type": "Pricebook2", "url": "/services/data/v36.0/sobjects/Pricebook2/01s36000004AGVLAA4" }, "Name": "UK Pricebook" } }] }; 
var y = json.records; 
alert(y); 
localStorage.setItem("offlinecurries1", JSON.stringify(y)); 
var x = JSON.parse(localStorage.getItem("offlinecurries1")); 
alert(x[0].Name);